RFR: 8322477: order of subclasses in the permits clause can differ between compilations [v3]

Vicente Romero vromero at openjdk.org
Wed Jan 10 03:48:42 UTC 2024


> This is a very interesting issue. Given code like:
> 
> sealed interface Sealed {
>     record R1() implements Sealed {}
>     record R2() implements Sealed {}
> }
> 
> 
> As we know javac will infer the `permits` clause of sealed interface `Sealed` logically the order should correspond to the order in which the permitted subclasses appear in the source code. Well it has been consistently observed by the reported of this bug, that some tools like Gradle while doing incremental compilation can make javac infer either `R1, R2` or `R2, R1` as permitted subclasses. The reason is not clear still under investigation on their side but the fact is that javac is generating inconsistent output for some classes with this shape. The proposed solution is to store the position of the permitted subclasses being discovered by javac so that the order of the permitted subclasses corresponds to the original order in the source file. Efforts to reduce the project where the issue was discovered to a small reproductor have been unsuccessful but the proposed patch have fixed the issue observed by the reporter.
> 
> TIA

Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:

  updating regression test

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/17284/files
  - new: https://git.openjdk.org/jdk/pull/17284/files/637f4241..20ff11bc

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

  Stats: 18 lines in 1 file changed: 10 ins; 7 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/17284.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/17284/head:pull/17284

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


More information about the compiler-dev mailing list