typetools/annotation-tools

insert-annotations-to-source may raise an exception depending on the class name

pbsf opened this issue · 10 comments

pbsf commented

Below I have two pairs of .jaif/.java files with similar content (almost empty).

MultiVersionControl.jaif:
package plume:
class MultiVersionControl:

MultiVersionControl.java:
package plume;
public class MultiVersionControl { }

MultiVersionControl2.jaif:
package plume:
class MultiVersionControl2:

MultiVersionControl2.java:
package plume;
public class MultiVersionControl2 { }

Even tough they have similar content, when trying to run the insert-annotations-to-source on both pairs only one of them succeed. On the other, I get an exception. Below is the log:

$ insert-annotations-to-source MultiVersionControl2.jaif MultiVersionControl2.java
Warning: IndexFileSpecification did not find classfile for: plume.MultiVersionControl2

$ insert-annotations-to-source MultiVersionControl.jaif MultiVersionControl.java
IndexFileSpecification had a problem reading class: plume.MultiVersionControl
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 758435786
at org.objectweb.asm.ClassReader.readInt(ClassReader.java:2003)
at annotations.io.classfile.CodeOffsetAdapter$1.readInt(CodeOffsetAdapter.java:90)
at annotations.io.classfile.CodeOffsetAdapter$1.visitTableSwitchInsn(CodeOffsetAdapter.java:180)
at annotator.scanner.MethodOffsetClassVisitor$MethodOffsetMethodVisitor.visitTableSwitchInsn(MethodOffsetClassVisitor.java:204)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:1249)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:445)
at annotator.specification.IndexFileSpecification.parseClass(IndexFileSpecification.java:175)
at annotator.specification.IndexFileSpecification.parseScene(IndexFileSpecification.java:150)
at annotator.specification.IndexFileSpecification.parse(IndexFileSpecification.java:103)
at annotator.Main.main(Main.java:566)

I'm attaching the files to make it easier to reproduce.
bug.zip

It might have to do with the fact that AFU uses plume-lib, and the plume-lib project has a plume.MultiVersionControl class. On the other hand, the bug does not arise on other classes from the plume-lib project.

The difference is due to plume.MultiVersionControl being on the classpath (in plume.jar) while plume.MultiVersionControl2 is not. If the latter is available, the same exception is thrown. The pending ASM 5.0 update may or may not fix the problem.

pbsf commented

I also ran insert-annotations-to-source for other files that are in the plume.jar classpath and had no issues. For example, I created the same empty .jaif/.java files with package plume and class name Option and had no issues. plume.Option is on the plume.jar.
I'm attaching this case here too.
Option.zip

Why is it different for the plume.MultiVersionControl?

The underlying cause of the crash is a bug in annotations.io.classfile.CodeOffsetAdapter (in scene-lib). The bug doesn't show up on visiting your empty class, but it does show up on visiting the class of the same name in plume-lib -- which obviously isn't the one you want to visit, so fixing that bug won't fix your problem.

I do have a workaround for you that I don't want to commit because it's not a foolproof solution: Edit annotation-file-utilities/scripts/insert-annotations-to-source and change the argument of -classpath in the last line to .:${CLASSPATH}:${ANNOTATION_FILE_UTILS}, thus putting your plume.MultiVersionControl ahead of the one in plume-lib.

pbsf commented

Thanks for looking into that Dan, but unfortunately this workaround did not work on my environment -- I changed the last line of the script but the exception is still thrown when running this script for plume.MultiVersionControl.

Is it the same code (modulo annotations) as the library version? If so,
that makes sense, and I'll definitely need to fix the underlying bug to
unblock you. If not, would you please send me the source and class files?

-- Dan.

On Mon, Dec 21, 2015 at 9:01 AM, Paulo Barros notifications@github.com
wrote:

Thanks for looking into that Dan, but unfortunately this workaround did
not work on my environment -- I changed the last line of the script but the
exception is still thrown when running this script for
plume.MultiVersionControl.


Reply to this email directly or view it on GitHub
#110 (comment)
.

pbsf commented

Even after modifying the insert-annotations-to-source script like you advised, the file attached on the first message of this thread (bug.zip) still throws an exception when I try to run:

$ insert-annotations-to-source MultiVersionControl.jaif MultiVersionControl.java

Do you have plume-lib in your CLASSPATH already? If so, ensure it's not in
the CLASSPATH and try again.

-- Dan.

On Mon, Dec 21, 2015 at 11:45 AM, Paulo Barros notifications@github.com
wrote:

Even after modifying the insert-annotations-to-source script like you
advised, the file attached on the first message of this thread (bug.zip)
still throws an exception when I try to run:

$ insert-annotations-to-source MultiVersionControl.jaif
MultiVersionControl.java


Reply to this email directly or view it on GitHub
#110 (comment)
.

pbsf commented

plume-lib was indeed on my CLASSPATH. I removed it but the error remains:

$ echo $CLASSPATH

$ insert-annotations-to-source MultiVersionControl.java MultiVersionControl.jaif
IndexFileSpecification had a problem reading class: plume.MultiVersionControl
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -2146924934
at org.objectweb.asm.ClassReader.readInt(ClassReader.java:2003)
...

I've fixed the bug that causes the crash, but I'm leaving this issue open until I have implemented a way to distinguish the analysis classpath from the runtime classpath.

pbsf commented

This has also been fixed on my environment since Dan's last message.