Re: ArrayIndexOutOfBoundsException

Evgeny Mandrikov <[email protected]> Tue, 10 Jul 2018 18:01:18 +0200
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <CAEPFu69jzT6uBD6qTM+s3tXx+7a_3TWgrcRm7RwccmQ++cDDpg@mail.gmail.com>
Hi Henry,

This looks very similar to https://github.com/jacoco/jacoco/issues/585
which is actually a bug in javac
https://bugs.openjdk.java.net/browse/JDK-8144185
fix was done in JDK 9 and backported to JDK 8u172.
This was also discussed in https://gitlab.ow2.org/asm/asm/issues/317789
that states "Adding workarounds for external bugs in ASM would not be an
incentive to fix the root cause of these bugs" and mentions some possible
workarounds for users of ASM who still want to deal with buggy class files
that were produces by buggy javac versions.
Hope this helps.

Regards,
Evgeny

On Tue, Jul 10, 2018 at 5:50 PM Henry Coles <[email protected]>
wrote:

> I've recently had a bug reported against a project I maintain that looks
> like it might be a bug in ASM (thanks for a great library by the way).
>
> https://github.com/hcoles/pitest/issues/481
>
> Reading the following class (from this project
> https://github.com/ReedOei/eunomia/blob/master/src/main/java/com/reedoei/eunomia/ast/resolved/ResolvedMethod.java
> )
>
> public class ResolvedMethod {
>     public final List<ResolvedMethodCall> methodCalls = new ArrayList<>();
>
>     public final MethodDeclaration base;
>     public final ResolvedMethodDeclaration declaration;
>
>     public ResolvedMethod(final MethodDeclaration base) {
>         this.base = base;
>
>         declaration = base.resolve();
>
>         for (final MethodCallExpr calls : base.findAll(MethodCallExpr.class)) {
>             methodCalls.add(new ResolvedMethodCall(calls));
>         }
>
>         // Sort by line, then by column.
>         methodCalls.sort((a, b) ->
>             new NOptionalBuilder<String, Range>().
>                     add("a", a.base.getRange())
>                     .add("b", b.base.getRange())
>                     .build()
>                     .fromOptional(0, m -> {
>                         final @Nullable Range aRange = m.get("a");
>                         final @Nullable Range bRange = m.get("b");
>
>                         if (aRange != null && bRange != null) {
>                             if (aRange.begin.line < bRange.begin.line ||
>                                     (aRange.begin.line == bRange.begin.line && aRange.begin.column < bRange.begin.column)) {
>                                 return -1;
>                             } else if (aRange.begin.line == bRange.begin.line &&
>                                     aRange.begin.column == bRange.begin.column){
>                                 return 0;
>                             } else {
>                                 return 1;
>                             }
>                         } else {
>                             return 0;
>                         }
>                     }));
>     }
> }
>
> Results in
>
> Caused by: java.lang.ArrayIndexOutOfBoundsException: 137
>     at org.pitest.reloc.asm.ClassReader.readLabel (ClassReader.java:2442)
>     at org.pitest.reloc.asm.ClassReader.createLabel (ClassReader.java:2458)
>     at org.pitest.reloc.asm.ClassReader.readTypeAnnotations (ClassReader.java:2524)
>     at org.pitest.reloc.asm.ClassReader.readCode (ClassReader.java:1688)
>     at org.pitest.reloc.asm.ClassReader.readMethod (ClassReader.java:1274)
>     at org.pitest.reloc.asm.ClassReader.accept (ClassReader.java:679)
>     at org.pitest.reloc.asm.ClassReader.accept (ClassReader.java:391)
>
> This is reproducible with both ASM 6.1.1 and 6.2.
>
> The issue seems to relate to the @Nullable annotations.
>
> Is this a known issue?
>
> The code used to read the class is here
>
>
> https://github.com/hcoles/pitest/blob/3e2e77fb38793f534a1bb93dff7d45c975764a57/pitest/src/main/java/org/pitest/classinfo/ClassInfoVisitor.java#L39
>
>
> Thanks
>
> Henry
>
> --
> You receive this message as a subscriber of the [email protected] mailing list.
> To unsubscribe: mailto:[email protected]
> For general help: mailto:[email protected]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>


-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws