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

Jan Lahoda jlahoda at openjdk.java.net
Fri May 13 08:58:45 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 two additional commits since the last revision:

 - 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/3e4a7401..00066f1b

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

  Stats: 506894 lines in 7080 files changed: 380732 ins; 62098 del; 64064 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