RFR: 8178701: Compile error with switch statement on protected enum defined in parent inner class [v3]

Jan Lahoda jlahoda at openjdk.java.net
Mon May 16 09:57:49 UTC 2022


> Consider the following code in two packages:
> 
> package foo;
> 
> import bar.D.E;
> 
> public class A {
> 
>     public static class B {
> 
>         protected enum C {
>             X, Y, Z
>         }
>     }
> 
>     public static void main(String... args) {
>         new E().run(B.C.X);
>     }
> }
> 
> 
> 
> package bar;
> 
> import foo.A.B;
> 
> public class D {
> 
>     public static class E extends B {
> 
>         public void run(C arg) {
>             switch (arg) {
>                 default:
>                     System.out.println("OK");
>             }
>         }
>     }
> }
> 
> 
> Accessing `foo.A.B.C` in `bar.D.E` is OK, as it is accessible through the `E`'s superclass. But, for the `switch`, javac creates a map (array) from runtime ordinals of constants of `E` to compile-time positions. But, this mapping is in a different class that does not extend `B`, so internal method lookups fail for it, as the methods are not accessible per Java rules.
> 
> But, at runtime, the enum class is effectively public, so I think it is possible to ignore the protected access rules and accept the method invocations while generatting the mapping code, which is what this patch is trying to do.

Jan Lahoda has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:

 - Merge branch 'master' into JDK-8178701
 - Merge branch 'master' into JDK-8178701
 - 8178701: Compile error with switch statement on protected enum defined in parent inner class

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/7621/files
  - new: https://git.openjdk.java.net/jdk/pull/7621/files/00066f1b..9bd1883a

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=7621&range=02
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=7621&range=01-02

  Stats: 69941 lines in 785 files changed: 45346 ins; 20733 del; 3862 mod
  Patch: https://git.openjdk.java.net/jdk/pull/7621.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/7621/head:pull/7621

PR: https://git.openjdk.java.net/jdk/pull/7621


More information about the compiler-dev mailing list