JDK-7101822 causes spurious 'annotation.type.not.applicable' error
Liam Miller-Cushon
cushon at google.com
Fri Jul 17 22:13:52 UTC 2015
Hi,
I think I found a regression introduced by the fix for JDK-7101822 [1][2]
[1] https://bugs.openjdk.java.net/browse/JDK-7101822
[2] http://hg.openjdk.java.net/jdk9/dev/langtools/rev/9d2192f36e53
The full repro is below. Symbol completion failures during import
processing are causing spurious 'annotation.type.not.applicable' errors. In
the repro, Check.annotationApplicable ends up getting called after a
completion failure has occurred during import processing. The type of 'Foo'
is recorded as the error type, so it doesn't match any of the accepted
target kinds for the @Retention annotation, so
'annotation.type.not.applicable' is reported.
The obvious fix would be to handle error types in
Check.annotationApplicable:
diff -r 9d2192f36e53 -r 2cbbecfacf02
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java Wed
Dec 03 13:46:12 2014 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java Fri
Jul 17 15:06:35 2015 -0700
@@ -3034,6 +3034,9 @@
targets[i] = e.value.name;
}
}
+ if (s.kind == ERR) {
+ return true; // recovery
+ }
for (Name target : targets) {
if (target == names.TYPE)
{ if (s.kind == TYP) return true; }
... but it might be better to change how errors are handled during import
processing.
Here's the repro:
=== p/Bar.java ===
package p;
public class Bar extends Super {}
=== p/Super.java ===
package p;
public class Super {
public static int CONST = 42;
}
=== Test.java ===
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Retention;
import static p.Bar.CONST;
@Retention(RetentionPolicy.RUNTIME)
@interface Foo {}
===
$ JAVAC=~/src/langtools9/dist/bootstrap/bin/javac
$ $JAVAC p/Bar.java p/Super.java
# Super is deliberately left out of lib.jar to trigger a completion failure
$ jar cf lib.jar p/Bar.class
$ $JAVAC -cp lib.jar -sourcepath : Test.java
Test.java:6: error: annotation type not applicable to this kind of
declaration
@Retention(RetentionPolicy.RUNTIME)
^
1 error
The error should be:
Test.java:4: error: cannot access Super
import static p.Bar.CONST;
^
class file for p.Super not found
1 error
Thanks,
Liam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150717/6568beef/attachment-0001.html>
More information about the compiler-dev
mailing list