RFR: 8287885: Local classes cause ClassLoader error if the type names are similar but not same

Archie L. Cobbs duke at openjdk.org
Wed Feb 22 16:12:08 UTC 2023


On Mon, 20 Feb 2023 20:50:48 GMT, Archie L. Cobbs <duke at openjdk.org> wrote:

> 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.

Withdrawing this PR - too much of a hack and it doesn't really solve the underlying problem.

To be discussed further on compiler-dev.

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

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


More information about the compiler-dev mailing list