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

Parser fails when encountering type annotation #15

Open
gunnarmorling opened this issue Oct 27, 2017 · 2 comments
Open

Parser fails when encountering type annotation #15

gunnarmorling opened this issue Oct 27, 2017 · 2 comments

Comments

@gunnarmorling
Copy link
Contributor

I've a specific usage of Java 8 type annotations (JSR 308) which makes the parser fail. To reproduce, parse these classes:

package com;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
public @interface SomeAnno {
}
package com;

public interface SomeInterface<T> {
	void foo();
}
package com;

class SomeImpl implements SomeInterface<Object @SomeAnno[]> {

	@Override
	public void foo() {
	}
}

That's the stacktrace I'm getting:

java.lang.StringIndexOutOfBoundsException: String index out of range: -29
	at java.lang.String.substring(String.java:1967)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.visitAnnotation(OracleJdkParserVisitor.kt:78)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.visitAnnotation(OracleJdkParserVisitor.kt:40)
	at com.netflix.devinsight.shaded.com.sun.tools.javac.tree.JCTree$JCAnnotation.accept(JCTree.java:2327)
	at com.netflix.devinsight.shaded.com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:68)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.convert(OracleJdkParserVisitor.kt:1026)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.convertAll(OracleJdkParserVisitor.kt:1058)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.visitMethod(OracleJdkParserVisitor.kt:617)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.visitMethod(OracleJdkParserVisitor.kt:40)
	at com.netflix.devinsight.shaded.com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:800)
	at com.netflix.devinsight.shaded.com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:68)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.convert(OracleJdkParserVisitor.kt:1026)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.convertPossibleMultiVariable(OracleJdkParserVisitor.kt:1082)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.visitClass(OracleJdkParserVisitor.kt:279)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.visitClass(OracleJdkParserVisitor.kt:40)
	at com.netflix.devinsight.shaded.com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:720)
	at com.netflix.devinsight.shaded.com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:68)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.convert(OracleJdkParserVisitor.kt:1026)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.convertAll(OracleJdkParserVisitor.kt:1058)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.visitCompilationUnit(OracleJdkParserVisitor.kt:311)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.visitCompilationUnit(OracleJdkParserVisitor.kt:40)
	at com.netflix.devinsight.shaded.com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:550)
	at com.netflix.devinsight.shaded.com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:68)
	at com.netflix.rewrite.parse.OracleJdkParser.parse(OracleJdkParser.kt:112)
	at com.netflix.rewrite.parse.AbstractParser.parse(Parser.kt:69)

Interestingly, it doesn't happen if I change the type of the annotated element from Object (or any other reference type) to a primitive type such as int.

@jkschneider
Copy link
Collaborator

I'm not even sure how to read that! What does that do?

@gunnarmorling
Copy link
Contributor Author

It applies that annotation to the component type of the given array type. What that means semantically, is up to the application using it of course.

A real-world example is Bean Validation 2.0, where we're using it to mark the value type emitted by a given value extractor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants