RFR: 8322477: order of subclasses in the permits clause can differ between compilations
Vicente Romero
vromero at openjdk.org
Fri Jan 5 17:48:46 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
-------------
Commit messages:
- 8322477: order of subclasses in the permits clause can differ between compilations
Changes: https://git.openjdk.org/jdk/pull/17284/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=17284&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8322477
Stats: 76 lines in 8 files changed: 38 ins; 0 del; 38 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