Incorrect 'sealed is not allowed here' compile-time error

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P2
    • 26
    • Affects Version/s: 25, 26
    • Component/s: tools
    • b06
    • Verified

        Consider code like:
        ```
        $ cat /tmp/T.java
        import java.lang.ref.*;
        public class T {
            public static void main(String[] args) {
                new WeakReference<>(null) {
                    private Object hardRef = null;
                };
            }
        }
        ```
        and compile it using current JDK 25 or current JDK 26:
        ```
        $ ./jdk-25/bin/javac -fullversion
        javac full version "25-ea+30-3419"
        $ ./jdk-25/bin/javac /tmp/T.java
        /tmp/T.java:4: error: modifier sealed not allowed here
                new WeakReference<>(null) {
                                          ^
        1 error
        $ ./jdk-26/bin/javac -fullversion
        javac full version "26-ea+5-453"
        $ ./jdk-26/bin/javac /tmp/T.java
        /tmp/T.java:4: error: modifier sealed not allowed here
                new WeakReference<>(null) {
                                          ^
        1 error
        ```

        This is obviously completely incorrect.

        Reported here:
        https://github.com/apache/netbeans/pull/8572#issuecomment-3046371322

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

                Created:
                Updated:
                Resolved: