RFR: 7016187: `javac -h` could generate conflict .h for inner class and class name with '_'

Jonathan Gibbons jjg at openjdk.org
Fri Feb 17 23:34:24 UTC 2023


On Thu, 16 Feb 2023 17:49:00 GMT, Archie L. Cobbs <duke at openjdk.org> wrote:

> Consider these two classes:
> 
> public class Foo_Bar {
>     public static native void method();
> }
> 
> 
> public class Foo {
>     public static class Bar {
>         public static native void method();
>     }
> }
> 
> If you run `javac -h` to generate native header files, classes `Foo_Bar` and `Foo$Bar` will want to generate the same native header file `Foo_Bar.h`.
> 
> Currently, javac does not detect this situation, so in effect you get a "last writer wins" situation.
> 
> This patch causes compilation to fail instead in this case with an error like this:
> 
> Foo.java:2: error: error while writing Bar: native header file collision between Foo_Bar and Foo$Bar (both generate Foo_Bar.h)
>     public static class Bar {
>                   ^
> 1 error

The JBS issue lists _two_ problem cases, of which this PR addresses one.

You should either fix both, or file a subsidiary issue for the part that is not covered here (if that is still an issue):

> It also does not handle the fields properly for O_I.class and O$I.class if both have same named fields. The generated field constant names are the same in the jni header file.

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

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


More information about the compiler-dev mailing list