RFR: 8264373: javac hangs when annotation is declared with sealed public modifier [v2]

Vicente Romero vromero at openjdk.java.net
Thu Apr 15 17:29:58 UTC 2021


> Please review this one liner fix. Although the title mentions the `sealed` modifier, the issue is not strictly related to it. Basically the situation is the following: modifiers `sealed` + `annotation` can't be applied together meaning that this declaration:
> 
> sealed public @interface SealedTest { }
> 
> 
> should be rejected by the compiler. We check this assertion at method: `Check::checkFlags` which then invokes `Check::checkDisjoint` which at the end invokes `TreeInfo::firstFlag` to find out what is the first low order bit set to 1 in the intersection between the current symbol flags and subset of them. Now the current implementation of this method is:
> 
> 
>     public static long firstFlag(long flags) {
>         long flag = 1;
>         while ((flag & flags & ExtendedStandardFlags) == 0)
>             flag = flag << 1;
>         return flag;
>     }
> 
> but given that `ExtendedStandardFlags` is defined as: `StandardFlags | DEFAULT | SEALED | NON_SEALED` and `StandardFlags` is: `0x0FFF` which if we intersect with the ANNOTATION flag (1<<13) will always return 0, the the loop executes forever. I guess we didn't see this issue before because we didn't had a constraint involving a flag with a value > 0x0FFF and less than 0xFFFF which is the case of the ANNOTATION flag. It seems to me that we can safely drop the `& ExtendedStandardFlags` in method `TreeInfo::firstFlag` given that it is used only by Check::checkDisjoint and it is invoked with an intersection of the current flags and the subset the invoking method cares about. So it won't be possible for the argument of `TreeInfo::firstFlag` to contain some javac internal flags we don't want a compiler user to see. What do you think?

Vicente Romero has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:

 - Merge branch 'master' into JDK-8264373
 - 8264373: javac hangs when annotation is declared with sealed public modifier

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/3273/files
  - new: https://git.openjdk.java.net/jdk/pull/3273/files/190ddd0a..9b5fb848

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3273&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3273&range=00-01

  Stats: 50947 lines in 1477 files changed: 34462 ins; 11107 del; 5378 mod
  Patch: https://git.openjdk.java.net/jdk/pull/3273.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/3273/head:pull/3273

PR: https://git.openjdk.java.net/jdk/pull/3273


More information about the compiler-dev mailing list