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

Resolving which generic method to call causes NPE during compilation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 8u25, 8u40
    • Fix Version/s: 9
    • Component/s: tools
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_25"
      Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      The java compiler generates a NPE when trying to compile the given source.
      May be related to
      http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8057800

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to compile given source code, like:
      $"C:\Program Files\Java\jdk1.8.0_25\bin\javac" CompilerBug.java


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      $"C:\Program Files\Java\jdk1.8.0_25\bin\javac" CompilerBug.java
      An exception has occurred in the compiler (1.8.0_25). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.NullPointerException
              at com.sun.tools.javac.code.Types.intersect(Types.java:3381)
              at com.sun.tools.javac.code.Types.lub(Types.java:3600)
              at com.sun.tools.javac.comp.Infer$InferenceStep$2.solve(Infer.java:1358)
              at com.sun.tools.javac.comp.Infer$InferenceContext.solveBasic(Infer.java:2247)
              at com.sun.tools.javac.comp.Infer$InferenceContext.access$600(Infer.java:1912)
              at com.sun.tools.javac.comp.Infer$GraphSolver.solve(Infer.java:1587)
              at com.sun.tools.javac.comp.Infer$InferenceContext.solve(Infer.java:2198)
              at com.sun.tools.javac.comp.Infer$InferenceContext.solve(Infer.java:2190)
              at com.sun.tools.javac.comp.Infer$InferenceContext.solve(Infer.java:2205)
              at com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:186)
              at com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:564)
              at com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:1431)
              at com.sun.tools.javac.comp.Resolve.findMethodInScope(Resolve.java:1618)
              at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1689)
              at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1662)
              at com.sun.tools.javac.comp.Resolve.findFun(Resolve.java:1822)
              at com.sun.tools.javac.comp.Resolve$8.doLookup(Resolve.java:2383)
              at com.sun.tools.javac.comp.Resolve$BasicLookupHelper.lookup(Resolve.java:3074)
              at com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3325)
              at com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3310)
              at com.sun.tools.javac.comp.Resolve.resolveMethod(Resolve.java:2379)
              at com.sun.tools.javac.comp.Attr.visitIdent(Attr.java:3170)
              at com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2011)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1843)
              at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:656)
              at com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1611)
              at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1296)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
              at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:692)
              at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1142)
              at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
              at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1035)
              at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
              at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4342)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4252)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4181)
              at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4156)
              at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1248)
              at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
              at com.sun.tools.javac.main.Main.compile(Main.java:523)
              at com.sun.tools.javac.main.Main.compile(Main.java:381)
              at com.sun.tools.javac.main.Main.compile(Main.java:370)
              at com.sun.tools.javac.main.Main.compile(Main.java:361)
              at com.sun.tools.javac.Main.compile(Main.java:56)
              at com.sun.tools.javac.Main.main(Main.java:42)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.concurrent.Callable;

      public class CompilerBug {

          public static <T> T execSafe(Callable<T> task, T defaultReturnValue) {
              return execSafe(task, defaultReturnValue, "");
          }

          public static <T> T execSafe(Callable<T> task, T defaultReturnValue, String errorMsg) {
              try {
                  return task.call();
              } catch (Exception e) {
                  System.err.println(errorMsg);
                  e.printStackTrace();
                  return defaultReturnValue;
              }
          }

          public static void execSafe(Runnable task, String errorMsg) {
              try {
                  task.run();
              } catch (Exception e) {
                  System.err.println(errorMsg);
                  e.printStackTrace();
              }
          }

          public static void main(String[] args) {
              new CompilerBug().callRunnable();
              new CompilerBug().callCallable();
          }

          private void callRunnable() {
              execSafe(() -> System.out.println("Hi, bugs!"), "Error occurred");
          }

          private Boolean callCallable() {
              return execSafe(() -> {
                  System.out.println("Hi, bugs!");
                  return false;
              }, null, "Error occurred");
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              vromero Vicente Arturo Romero Zaldivar
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: