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

javac Null Pointer Exception in Types.erasure

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Version:
      11

      Description

      A DESCRIPTION OF THE PROBLEM :
      The code example compiles fine with java8 and java13+, but fails with java11 (LTS). It also fails with the latest 11.0.7.

      REGRESSION : Last worked in version 8u241

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Prepare a directory "example" containing the three java source files listed below. Then run:
      javac example/Example.java example/Mapper.java


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      javac should compile the code.
      ACTUAL -
      javac gave the error output below:

      An exception has occurred in the compiler (11.0.7). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.NullPointerException
      at jdk.compiler/com.sun.tools.javac.code.Types.erasure(Types.java:2340)
      at jdk.compiler/com.sun.tools.javac.code.Types$14.visitTypeVar(Types.java:2398)
      at jdk.compiler/com.sun.tools.javac.code.Types$14.visitTypeVar(Types.java:2348)
      at jdk.compiler/com.sun.tools.javac.code.Type$TypeVar.accept(Type.java:1654)
      at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4857)
      at jdk.compiler/com.sun.tools.javac.code.Type$StructuralTypeMapping.visitMethodType(Type.java:282)
      at jdk.compiler/com.sun.tools.javac.code.Type$StructuralTypeMapping.visitMethodType(Type.java:230)
      at jdk.compiler/com.sun.tools.javac.code.Type$MethodType.accept(Type.java:1448)
      at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4857)
      at jdk.compiler/com.sun.tools.javac.code.Types.erasure(Types.java:2343)
      at jdk.compiler/com.sun.tools.javac.code.Types.erasure(Types.java:2329)
      at jdk.compiler/com.sun.tools.javac.code.Types.isSubSignature(Types.java:2748)
      at jdk.compiler/com.sun.tools.javac.code.Types.isSubSignature(Types.java:2744)
      at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.overrides(Symbol.java:1820)
      at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.overrides(Symbol.java:1792)
      at jdk.compiler/com.sun.tools.javac.code.Types$ImplementationCache.implementationInternal(Types.java:2932)
      at jdk.compiler/com.sun.tools.javac.code.Types$ImplementationCache.get(Types.java:2917)
      at jdk.compiler/com.sun.tools.javac.code.Types.implementation(Types.java:2952)
      at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.implementation(Symbol.java:1892)
      at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.implementation(Symbol.java:1885)
      at jdk.compiler/com.sun.tools.javac.comp.Resolve.notOverriddenIn(Resolve.java:455)
      at jdk.compiler/com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:1553)
      at jdk.compiler/com.sun.tools.javac.comp.Resolve.findMethodInScope(Resolve.java:1733)
      at jdk.compiler/com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1823)
      at jdk.compiler/com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1776)
      at jdk.compiler/com.sun.tools.javac.comp.Resolve$10.doLookup(Resolve.java:2654)
      at jdk.compiler/com.sun.tools.javac.comp.Resolve$BasicLookupHelper.lookup(Resolve.java:3293)
      at jdk.compiler/com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3543)
      at jdk.compiler/com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2651)
      at jdk.compiler/com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2645)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.selectSym(Attr.java:3721)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3601)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2114)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2006)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:695)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1174)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:956)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:743)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1294)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1020)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1098)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4683)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4574)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4503)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:4448)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1341)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
      at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
      at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)


      ---------- BEGIN SOURCE ----------
      -----
      example/Exampe.java:

      package example;

      public class Example {
          <T extends Number> T doSomething(final Number n, final Mapper<? super Number, ? extends T> mapper) {
              final T t = mapper.apply(n);
              return t;
          }
      }

      -----

      example/Mapper.java:

      package example;

      import java.util.Collections;
      import java.util.Iterator;
      import java.util.Objects;
      import java.util.function.Function;
      import java.util.function.Predicate;

      import java.lang.annotation.ElementType;
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;
      import java.lang.annotation.Target;

      @FunctionalInterface
      interface Mapper<I, O> extends Function<I, @Nullable O> {

          @Override
          O apply(I i);

          static <T> Iterator<T> apply(Iterator<? extends T> iter, int count) {
              return Collections.emptyIterator();
          }
      }

      @Retention(RetentionPolicy.RUNTIME)
      @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
      @interface Nullable {
          
      }
      -----
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      * The order of the files matter. If Mapper.java is given first to javac, then the problem doesn't appear.
      * Remove the annotation "@Nullable" for the type param "O" in Mapper.java
      * Rename the 2nd "apply" method, so that it doesn't overload Function::apply anymore.

      FREQUENCY : always


        Attachments

        1. Example.java
          0.2 kB
        2. Mapper.java
          0.7 kB

          Issue Links

            Activity

              People

              Assignee:
              asotona Adam Sotona
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: