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

An anonymous class is erroneously being classify as an abstract class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 26
    • 25
    • tools
    • b06

        javac is failing to compile this code:

        abstract class Base<T> {}
        abstract class Derived1<T> extends Base<T> {}
        abstract class Derived2<T> extends Base<T> {
            Derived2(Derived1<T> obj) {}
        }

        class Test {
            Base<String> obj = new Derived2<>(new Derived1<>() { /* not abstract */ }) { /* not abstract */ };
        }

        issuing error message:

        Test.java:8: error: Derived1 is abstract; cannot be instantiated
            Base<String> obj = new Derived2<>(new Derived1<>() { /* not abstract */ }) { /* not abstract */ };

        basically during speculative attribution the class body of the anonymous classes above is removed to avoid side-effects during the process. It seems like we are checking this condition on a speculative version of the anonymous class

        reported in compiler-dev: https://mail.openjdk.org/pipermail/compiler-dev/2025-June/030916.html

              vromero Vicente Arturo Romero Zaldivar
              vromero Vicente Arturo Romero Zaldivar
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: