JDK-7101822 causes spurious 'annotation.type.not.applicable' error

Jan Lahoda jan.lahoda at oracle.com
Mon Jul 20 07:27:31 UTC 2015


Hi Liam,

Thanks for the report. I've filled:
https://bugs.openjdk.java.net/browse/JDK-8131915

The problem seems to be in an inappropriate handling of the 
CompletionFailure that is triggered due to the missing class. I think it 
needs to be caught and a proper error reported for it.

Thanks,
     Jan

On 18.7.2015 00:13, Liam Miller-Cushon wrote:
> 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.javaWed
> Dec 03 13:46:12 2014 +0100
> +++
> b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.javaFri
> Jul 17 15:06:35 2015 -0700
> @@ -3034,6 +3034,9 @@
>                   targets[i] = e.value.name <http://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


More information about the compiler-dev mailing list