RFR: 8191460: crash in Annotate with duplicate declaration and annotation processing enabled [v3]

Vicente Romero vromero at openjdk.org
Tue Nov 7 20:00:24 UTC 2023


> This PR is removing an assertion in `com.sun.tools.javac.comp.Annotate`. The assertion is being thrown for a special, corner-ish, case. Basically having:
> 
> package p;
> @Deprecated class T {}  // see that class T is annotated
> 
> and:
> 
> package p;
> class Y {
>     @interface A {}
>     @interface A {} // error: class A is already defined
>     T t;
> }
> 
> class `Y` has a duplicate definition of annotation `A`. Now if class `T` is compiled first as in:
> 
> `javac -d out/ p/T.java`
> 
> and then we do:
> `javac -processor P -cp p:out/:. p/Y.java p/T.java`
> 
> where P is the simplest possible annotation processor, basically doing nothing. IMO what is happening here is that during the second compilation, once the compiler find type `T` in class `Y`, given that T.class is in the classpath, it is loaded and the `@Deprecated` annotation is attached to symbol for type `T`. Then when the source for `T.java` is being compiled and its annotations are being processed we get to the code where the assertion is. Here the symbol for `T` is not a package but its metadata is not empty and so the assertion is thrown. The fix here is just removing the assertion as as shown by this example it is not an invariant.
> 
> TIA

Vicente Romero has updated the pull request incrementally with two additional commits since the last revision:

 - Merge pull request #2 from lahodaj/JDK-8191460
   
   Attempting to improve the fix.
 - Attempting to improve the fix.

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/16443/files
  - new: https://git.openjdk.org/jdk/pull/16443/files/39a9bfb2..f32d464e

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=16443&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=16443&range=01-02

  Stats: 38 lines in 3 files changed: 21 ins; 4 del; 13 mod
  Patch: https://git.openjdk.org/jdk/pull/16443.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/16443/head:pull/16443

PR: https://git.openjdk.org/jdk/pull/16443


More information about the compiler-dev mailing list