Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8277105

Inconsistent handling of missing permitted subclasses

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P3
    • Resolution: Fixed
    • 17, 18
    • 18
    • tools
    • None
    • b27

    Description

      Consider code like:
      lib:
      ---
      public abstract sealed class Lib permits Impl1, Impl2 {}
      final class Impl1 extends Lib {}
      final class Impl2 extends Lib {}
      ---
      test:
      ---
      public class Test1 {
          public void test(Lib lib) {
              Runnable r = (Runnable) lib;
          }
      }
      public class Test2 {
          public void test(Lib lib) {
              switch (lib) {
                  case Impl2 i -> {}
              }
          }
      }
      ---

      If Impl1 is missing, the behavior differs:
      ---
      $ javac -d out -classpath out --enable-preview -source 17 test/Test1.java
      test/Test1.java:3: error: cannot access Impl1
              Runnable r = (Runnable) lib;
                           ^
        class file for Impl1 not found
      1 error
      ---
      $ javac -d out -classpath out --enable-preview -source 17 test/Test2.java
      test/Test2.java:3: error: the switch statement does not cover all possible input values
              switch (lib) {
              ^
      Note: test/Test2.java uses preview features of Java SE 17.
      Note: Recompile with -Xlint:preview for details.
      1 error
      ---

      The switch handling should be more consistent with the case, and should report an error on missing classfiles for the permitted subtypes.

      Attachments

        Issue Links

          Activity

            People

              jlahoda Jan Lahoda
              jlahoda Jan Lahoda
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: