RFR: 8287885: Local classes cause ClassLoader error if the type names are similar but not same
Archie L. Cobbs
duke at openjdk.org
Mon Feb 20 20:57:18 UTC 2023
The compiler doesn't really support case-insensitive filesystems. However, we can still avoid name clashes for local classes because their names are synthesized with indexed names like`$1`, `$2`, etc.
So previously, a class like this:
public class Test {
void method1() {
enum ABC { A, B, C; };
}
void method2() {
enum Abc { A, B, C; };
}
}
would generate these classfiles:
Test.class
Test$1ABC.class
Test$1Abc.class
the latter two of which clash on case-insensitive filesystems. After this patch, these non-clashing classfiles are generated instead:
Test.class
Test$1ABC.class
Test$2Abc.class
The only thing slightly wonky about this patch is that `clearLocalClassNameIndexes()` since local classes `ABC` and `Abc` share the same index, clearing either one clears both. But this is harmless, because these indexes are cleared in a batch, during a final "cleanup" step after processing the containing class.
To avoid any locale weirdness, we only collapse ASCII letters A-Z/a-z. So this is clearly a limited, tactical fix.
-------------
Commit messages:
- Fix typo in comment.
- Avoid local class classfile name clashes on case-insensitive filesystems.
Changes: https://git.openjdk.org/jdk/pull/12678/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=12678&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8287885
Stats: 26 lines in 1 file changed: 23 ins; 1 del; 2 mod
Patch: https://git.openjdk.org/jdk/pull/12678.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/12678/head:pull/12678
PR: https://git.openjdk.org/jdk/pull/12678
More information about the compiler-dev
mailing list