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

NPE:Cannot invoke "com.sun.tools.javac.code.Type.isPrimitive() because t is null

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Java version:

      openjdk version "16" 2021-03-16
      OpenJDK Runtime Environment (build 16+36-2231)
      OpenJDK 64-Bit Server VM (build 16+36-2231, mixed mode, sharing)

      (The same issues also present in OpenJDK 15.0.2 - confirmed).

      OS: macOS Mojave (10.14).


      A DESCRIPTION OF THE PROBLEM :
      This is a compiler error, not runtime error. The code I have (see the source code section below) list the relevant classes.

      The code that triggered this error is not supposed to be compilable, but the compiler crashes with this error message even before compilation is complete:

      "java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Type.isPrimitive()" because "t" is null".

      The full diagnostic is as follows:

      An exception has occurred in the compiler (16). 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, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
      java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Type.isPrimitive()" because "t" is null
              at jdk.compiler/com.sun.tools.javac.code.Types.eraseNotNeeded(Types.java:2384)
              at jdk.compiler/com.sun.tools.javac.code.Types.erasure(Types.java:2377)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.visitIterableForeachLoop(Lower.java:3500)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.visitForeachLoop(Lower.java:3376)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCEnhancedForLoop.accept(JCTree.java:1187)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2081)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:167)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:3561)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1047)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2081)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:150)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2736)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2648)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:893)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2081)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2223)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:790)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2081)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2100)
              at jdk.compiler/com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:4027)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1588)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1435)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
              at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
              at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:169)
              at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:785)
              at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
              at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
              at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
              at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
              at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
              at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
              at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
              at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
              at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
              at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
              at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
              at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
              at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.base/java.lang.reflect.Method.invoke(Method.java:567)
              at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
              at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
              at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
              at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)

      NOTE: I am using Maven to trigger the build.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The source files listed below contains the bare minimum that I thought would be useful for this bug.

      The code is trivial - just practising some basic design patterns, and I have my own iterable class, MyIterable, that extends from java.lang.Iterable. (Please note that the original code just used java.lang.Iterable and java.lang.Iterator, and I was transitioning it to use my own iterable and iterator classes).

      The problem, as I could narrrow down, is the for-each loop in the main class, IteratorDemo. If the for-each loop is commented out, I get the usual compilation errors ("class is not abstract and doesn't override..."), which is as expected. With the for-each loop in place, the compiler crashes. This is also confirmed by the diagnostic error message above.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The expectation is that the code, as presented here, should throw the normal and expected compilation errors instead of crashing the compiler.
      ACTUAL -
      The compiler crashes with a NullPointerException during compilation.

      ---------- BEGIN SOURCE ----------
      // MyIterable.java

      package com.z0ltan.designpatterns.behavioural.iterator;
       
      public interface MyIterable<T> extends Iterable<T> {
        MyIterator<T> iterator();
      }

      // IteratorDemo (the Main class)

      package com.z0ltan.designpatterns.behavioural.iterator;

      public class IteratorDemo {
        public static void main(String[] args) {
          final Range range = new Range(2, 11);

         // this for-each loops triggers the NPE during the type-checking phase
          for (int e : range) {
            System.out.printf("%d ", e);
          }
          System.out.println();

          final MyIterator<Integer> it = range.iterator();
          while (it.hasNext()) {
            System.out.printf("%d ", it.next());
          }
          System.out.println();
        }
      }


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

      FREQUENCY : always


        Attachments

          Issue Links

            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: