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

Compiler crashes with NPE when using diamond operator and JAX-RS's GenericType

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      OS X 10.13.3 (17D47)
      tested on java 9, 10 and early access 11.

      A DESCRIPTION OF THE PROBLEM :
      Javac will fail with an NPE (version 9, 10 and 11) with code that worked on java 1.8.
      I managed to reproduce this only when using GenericType (https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/GenericType.html) together with a diamond operator.
      in short the following code won't compile and raise NPE from javac:
      final Wrapper<SimpleModel> exampleOneFail = staticFunc(new GenericType() {})

      REGRESSION : Last worked in version 8u172

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Trying to compile the code I added below will cause an NPE from javac

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      javac should compile successfully as happens when adding the workaround
      ACTUAL -
      [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ compiler-bug ---
      [INFO] Changes detected - recompiling the module!
      [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
      [INFO] Compiling 1 source file to /.../JavaCompilerBug/target/classes
      compiler message file broken: key=compiler.misc.msg.bug arguments=11-ea, {1}, {2}, {3}, {4}, {5}, {6}, {7}
      java.lang.NullPointerException
              at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitApply(Flow.java:1235)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
              at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitVarDef(Flow.java:989)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:956)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
              at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitBlock(Flow.java:997)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1020)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
              at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitMethodDef(Flow.java:964)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
              at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitClassDef(Flow.java:927)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
              at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.analyzeTree(Flow.java:1327)
              at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.analyzeTree(Flow.java:1317)
              at jdk.compiler/com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:218)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1401)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1375)
              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.handleExceptions(JavacTaskImpl.java:147)
              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:134)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
              at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
              at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
              at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
              at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
              at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
              at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
              at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
              at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
              at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
              at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.base/java.lang.reflect.Method.invoke(Method.java:566)
              at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
              at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
              at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
              at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
      [INFO] -------------------------------------------------------------
      [ERROR] COMPILATION ERROR :
      [INFO] -------------------------------------------------------------
      [ERROR] An unknown compilation problem occurred
      [INFO] 1 error
      [INFO] -------------------------------------------------------------
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD FAILURE
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 1.421 s
      [INFO] Finished at: 2018-05-28T18:55:55+02:00
      [INFO] Final Memory: 11M/47M
      [INFO] ------------------------------------------------------------------------
      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project compiler-bug: Compilation failure
      [ERROR] An unknown compilation problem occurred


      ---------- BEGIN SOURCE ----------
      pom.xml:
      ------------
      <?xml version="1.0"?>
      <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns="http://maven.apache.org/POM/4.0.0"
               xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

        <modelVersion>4.0.0</modelVersion>
        <name>compiler-bug</name>
        <artifactId>compiler-bug</artifactId>
        <groupId>com.fashiontrade</groupId>
        <packaging>jar</packaging>
        <version>1</version>

        <properties>
          <maven.compiler.source>10</maven.compiler.source>
          <maven.compiler.target>10</maven.compiler.target>
          <mainClass>com.fashiontrade.service.order.OrderService</mainClass>
          <src.dir>src/</src.dir>
        </properties>

        <dependencies>
          <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>2.27</version>
          </dependency>
        </dependencies>

        <build>
          <sourceDirectory>${src.dir}</sourceDirectory>
        </build>
      </project>

      Main.java:
      -------------
      import javax.ws.rs.core.GenericType;

      public class Main {
        public static void main(String[] args) {
          // This WILL cause NPE from javac
          final Wrapper<SimpleModel> exampleOneFail = BugCreator.get(new GenericType<>() {});

          // This WONT cause NPE from javac
      // final Wrapper<SimpleModel> exampleOneSuccess = BugCreator.func(new GenericType<Wrapper<SimpleModel>>() {});

      // This WILL cause NPE from javac
      // final Wrapper<SimpleModel> exampleTwoFail = func(new GenericType<>() {});

          // This WONT cause NPE from javac
      // final Wrapper<SimpleModel> exampleTwoSuccess = func(new GenericType<Wrapper<SimpleModel>>() {});
        }

        public static <T> T func(final GenericType<T> typeHolder) {
          return null;
        }
      }

      class BugCreator {

        public static <T> T get(final GenericType<T> typeHolder) {
          return null;
        }
      }

      class Wrapper<T> {

      }

      class SimpleModel {

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      import javax.ws.rs.core.GenericType;

      public class Main {
        public static void main(String[] args) {
          final Wrapper<SimpleModel> exampleOneSuccess = BugCreator.func(new GenericType<Wrapper<SimpleModel>>() {});
      }

        public static <T> T func(final GenericType<T> typeHolder) {
          return null;
        }
      }

      class BugCreator {

        public static <T> T get(final GenericType<T> typeHolder) {
          return null;
        }
      }

      class Wrapper<T> {

      }

      class SimpleModel {

      }


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                fmatte Fairoz Matte
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: