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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 26
    • 25, 26
    • tools
    • None
    • master

        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

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

                Created:
                Updated:
                Resolved: