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

AssertionError: Cannot add metadata to an intersection type

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b24

      Backports

        Description

        javac crashes on the program, which contains a type annotation on a local variable with an inferred intersection type.

        ```
        import java.lang.annotation.ElementType;
        import java.lang.annotation.Target;

        @Target({ElementType.TYPE_USE, ElementType.LOCAL_VARIABLE})
        @interface A {}

        class T {

          void t() {
            @A var c = g(1, 1L);
          }

          <X> X g(X a, X b) {
            return a;
          }
        }
        ```

        ```
        javac -fullversion T.java
        javac full version "16-ea+34-2216"
        ...
        java.lang.AssertionError: Cannot add metadata to an intersection type
                at jdk.compiler/com.sun.tools.javac.code.Type$IntersectionClassType.cloneWithMetadata(Type.java:1257)
                at jdk.compiler/com.sun.tools.javac.code.Type$IntersectionClassType.cloneWithMetadata(Type.java:1239)
                at jdk.compiler/com.sun.tools.javac.code.Type.annotatedType(Type.java:402)
                at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions$1.visitClassType(TypeAnnotations.java:626)
                at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions$1.visitClassType(TypeAnnotations.java:620)
                at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1010)
                at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.typeWithAnnotations(TypeAnnotations.java:702)
                at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.typeWithAnnotations(TypeAnnotations.java:537)
                at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.separateAnnotationsKinds(TypeAnnotations.java:358)
                at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitVarDef(TypeAnnotations.java:1266)
        ```

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                vromero Vicente Arturo Romero Zaldivar
                Reporter:
                cushon Liam Miller-Cushon
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: