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

NullPointerException when compiling a simple generic method

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_11"
      Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
      Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP Professional Version 2002 Service Pack 2

      A DESCRIPTION OF THE PROBLEM :
      When trying to compile java code with a simple generic method javac throws NullPointerException and produces no class files.

      The code and the stacktrace are attached to the report.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      just run javac against the given source code file

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Get working class files

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.NullPointerException
              at com.sun.tools.javac.comp.Flow.visitApply(Flow.java:1117)
              at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1210)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:35)
              at com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:157)
              at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1074)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:35)
              at com.sun.tools.javac.comp.Flow.scanStat(Flow.java:484)
              at com.sun.tools.javac.comp.Flow.scanStats(Flow.java:492)
              at com.sun.tools.javac.comp.Flow.visitBlock(Flow.java:747)
              at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:739)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:35)
              at com.sun.tools.javac.comp.Flow.scanStat(Flow.java:484)
              at com.sun.tools.javac.comp.Flow.visitIf(Flow.java:1073)
              at com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1050)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:35)
              at com.sun.tools.javac.comp.Flow.scanStat(Flow.java:484)
              at com.sun.tools.javac.comp.Flow.scanStats(Flow.java:492)
              at com.sun.tools.javac.comp.Flow.visitBlock(Flow.java:747)
              at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:739)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:35)
              at com.sun.tools.javac.comp.Flow.scanStat(Flow.java:484)
              at com.sun.tools.javac.comp.Flow.visitForeachLoop(Flow.java:864)
              at com.sun.tools.javac.tree.JCTree$JCEnhancedForLoop.accept(JCTree.java:849)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:35)
              at com.sun.tools.javac.comp.Flow.scanStat(Flow.java:484)
              at com.sun.tools.javac.comp.Flow.scanStats(Flow.java:492)
              at com.sun.tools.javac.comp.Flow.visitBlock(Flow.java:747)
              at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:739)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:35)
              at com.sun.tools.javac.comp.Flow.scanStat(Flow.java:484)
              at com.sun.tools.javac.comp.Flow.visitMethodDef(Flow.java:693)
              at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:639)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:35)
              at com.sun.tools.javac.comp.Flow.visitClassDef(Flow.java:641)
              at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:575)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:35)
              at com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:1256)
              at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1090)
              at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1064)
              at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:765)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:730)
              at com.sun.tools.javac.main.Main.compile(Main.java:353)
              at com.sun.tools.javac.main.Main.compile(Main.java:279)
              at com.sun.tools.javac.main.Main.compile(Main.java:270)
              at com.sun.tools.javac.Main.compile(Main.java:69)
              at com.sun.tools.javac.Main.main(Main.java:54)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.ArrayList;
      import java.util.List;
      import java.util.Map;
      import java.util.TreeMap;
      /*
       * JavacBug.java
       *
       */

      /**
       *
       * @author Daniil Elovkov
       */
      public class JavacBug {
          
          // function to transform a list of things augmented with key to a map of lists

          // THIS METHOD IS THE PROBLEM

          private <T> Map<String,List<T>> listToListMap(List<Keyed<? extends T>> list ) {
              
              Map<String,List<T>> map = new TreeMap<String,List<T>>();
              
              for (Keyed<? extends T> pair: list) {
                  
                  List<T> l = map.get(pair.key);
                  
                  if (l == null) {
                      l = new ArrayList<T>( );
                      l.add( pair.val );
                      map.put( pair.key, l );
                  } else {
                      l.add( pair.val );
                  }
                  
              }
              
              return map;
          }
          
      }

      class Keyed<T extends MyClass> {
          String key;
          T val;
      }

      class MyClass {
      }

      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: