Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type annotations cause ArrayIndexOutOfBoundsException in ASM ClassReader [SPR-14089] #18661

Closed
spring-issuemaster opened this issue Mar 26, 2016 · 4 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Mar 26, 2016

Tom van den Berge opened SPR-14089 and commented

I'm getting an exception when starting up my Spring Boot application:

java.lang.ArrayIndexOutOfBoundsException: 193
	at org.springframework.asm.ClassReader.readLabel(ClassReader.java:2185)
	at org.springframework.asm.ClassReader.readTypeAnnotations(ClassReader.java:1614)
	...

It seems that when my classes are inspected for annotations, ClassReader (Spring 4.2.5) chokes on one of my classes containing Java-8 type annotations. This is extremely unfortunate, because it means that I can't use Spring annotations in combination with type annotations.

I've attached a very small (maven) project that reproduces the problem. All you need to do is run "mvn test". The included unit test attempts to read the problematic class file using org.springframework.asm.ClassReader, and gives the same exception as above.

The class that can't be read is

public class Problem implements Interface<String> {
	public void serialize(String request) {
		Map<String, @Nullable Object> values = new HashMap<>();
		values.clear();
	}
}

The @Nullable type annotation is from org.eclipse.jdt.annotation 2.0.0. I've included the source code in the attached project.

And the interface:

public interface Interface<T> {
	void serialize(T request);
}

Without the interface, the problem doesn't occur. Also the type parameter is essential to reproduce the problem.
What is also surprising, is that when the class is not compiled by maven (javac), but by Eclipse, the problem does not occur.

It would be great to know if there is a workaround for this problem, e.g. compiler settings that can be included in the pom file.


Affects: 4.2.5

Attachments:

Issue Links:

  • #21999 Type annotations and generic types causing ArrayIndexOutOfBoundsException
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 26, 2016

Juergen Hoeller commented

Technically, this is an issue in ASM which we're forking there, currently at ASM 5.0.4 level. As of Spring Framework 4.3, this is based on ASM 5.1... However, your issue doesn't seem to be addressed there either yet, and I'm not aware of a workaround either.

So we can certainly address this in a custom fashion within our ASM fork, through a defensive catch block around type annotation parsing (and possibly similar metadata that Spring does not actually need for its component introspection, which is the only purpose of our repackaged ASM ClassReader). We'll do this for 4.3 RC1 as well as 4.2.6.

However, please also report this issue to the ASM project itself at the ObjectWeb tracker: http://forge.ow2.org/tracker/?group_id=23

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 27, 2016

Tom van den Berge commented

Great! I just filed the bug there, too:

http://forge.ow2.org/tracker/index.php?func=detail&aid=317615&group_id=23&atid=100023

I was able to reproduce the bug against ASM 5.0.4 and ASM 5.1 directly as well.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 29, 2016

Juergen Hoeller commented

We're leniently handling any label offset mismatch now. Please give it a try against the upcoming 4.3.0.BUILD-SNAPSHOT; to be backported to 4.2.6 in a bit.

Once ASM published an official fix for the actual cause of the mismatch, we'll roll it in as well.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 30, 2016

Tom van den Berge commented

It works fine in 4.3.0.BUILD-SNAPSHOT.

Thanks a lot for the incredibly fast fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.