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

Jshell crashing when trying to create a self referencing variable using var

XMLWordPrintable

    • b15
    • 16
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      In jshell upon trying to create a self referencing variable with the var keyword jshell crashes. According to the stacktrace this is because of a NullPointerException when trying to infer the type of the variable which is null because it is not defined until now.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Open jshell and enter:

      var a = a;

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      An error message, explaining that the variable cannot be created
      ACTUAL -
      Exception in thread "main" java.lang.InternalError: Exception during analyze - java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Type.baseType()" because "tree.init.type" is null
              at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.analyze(TaskFactory.java:393)
              at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.<init>(TaskFactory.java:384)
              at jdk.jshell/jdk.jshell.TaskFactory.lambda$analyze$1(TaskFactory.java:177)
              at jdk.jshell/jdk.jshell.TaskFactory.lambda$runTask$4(TaskFactory.java:212)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskPool.getTask(JavacTaskPool.java:193)
              at jdk.jshell/jdk.jshell.TaskFactory.runTask(TaskFactory.java:205)
              at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:174)
              at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:160)
              at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:149)
              at jdk.jshell/jdk.jshell.Eval.trialCompile(Eval.java:735)
              at jdk.jshell/jdk.jshell.Eval.processVariables(Eval.java:326)
              at jdk.jshell/jdk.jshell.Eval.lambda$sourceToSnippets$1(Eval.java:218)
              at jdk.jshell/jdk.jshell.TaskFactory.lambda$parse$6(TaskFactory.java:254)
              at jdk.jshell/jdk.jshell.TaskFactory.lambda$runTask$4(TaskFactory.java:212)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskPool.getTask(JavacTaskPool.java:193)
              at jdk.jshell/jdk.jshell.TaskFactory.runTask(TaskFactory.java:205)
              at jdk.jshell/jdk.jshell.TaskFactory.parse(TaskFactory.java:139)
              at jdk.jshell/jdk.jshell.TaskFactory.parse(TaskFactory.java:239)
              at jdk.jshell/jdk.jshell.Eval.sourceToSnippets(Eval.java:194)
              at jdk.jshell/jdk.jshell.Eval.eval(Eval.java:130)
              at jdk.jshell/jdk.jshell.JShell.eval(JShell.java:493)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSource(JShellTool.java:3618)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSourceCatchingReset(JShellTool.java:1342)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processInput(JShellTool.java:1240)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.run(JShellTool.java:1211)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.start(JShellTool.java:995)
              at jdk.jshell/jdk.internal.jshell.tool.JShellToolBuilder.start(JShellToolBuilder.java:261)
              at jdk.jshell/jdk.internal.jshell.tool.JShellToolProvider.main(JShellToolProvider.java:120)
      Caused by: java.lang.IllegalStateException: java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Type.baseType()" because "tree.init.type" is null
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:383)
              at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.analyze(TaskFactory.java:390)
              ... 27 more
      Caused by: java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Type.baseType()" because "tree.init.type" is null
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1317)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1027)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:677)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:751)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:770)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1448)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:677)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:751)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1238)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:921)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:677)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:751)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5478)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5369)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5200)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5145)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1317)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1290)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:404)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$analyze$1(JavacTaskImpl.java:379)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:379)
              ... 28 more

      ---------- BEGIN SOURCE ----------
      var a = a;
      ---------- END SOURCE ----------

      FREQUENCY : always


            jlahoda Jan Lahoda
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: