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

jshell - crash on 'new Object().""'

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 23
    • 22, 23
    • tools
    • 22

      After JDK-8315457, jshell crashes when the target of a StringTemplate is not a processor type:

      jshell> new Object().""Fatal Error: Unable to find method process

      Fatal Error: Unable to find method process
      Exception in thread "main" java.lang.InternalError: Exception during analyze - com.sun.tools.javac.util.FatalError: Fatal Error: Unable to find method process
              at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.analyze(TaskFactory.java:420)
              at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.<init>(TaskFactory.java:411)
              at jdk.jshell/jdk.jshell.TaskFactory.lambda$analyze$1(TaskFactory.java:183)
              at jdk.jshell/jdk.jshell.TaskFactory.lambda$runTask$4(TaskFactory.java:218)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskPool.getTask(JavacTaskPool.java:193)
              at jdk.jshell/jdk.jshell.TaskFactory.runTask(TaskFactory.java:211)
              at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:180)
              at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:166)
              at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:155)
              at jdk.jshell/jdk.jshell.ExpressionToTypeInfo.expressionInfo(ExpressionToTypeInfo.java:240)
              at jdk.jshell/jdk.jshell.Eval.processExpression(Eval.java:615)
              at jdk.jshell/jdk.jshell.Eval.lambda$sourceToSnippets$1(Eval.java:223)
              at jdk.jshell/jdk.jshell.TaskFactory.lambda$parse$6(TaskFactory.java:260)
              at jdk.jshell/jdk.jshell.TaskFactory.lambda$runTask$4(TaskFactory.java:218)
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskPool.getTask(JavacTaskPool.java:193)
              at jdk.jshell/jdk.jshell.TaskFactory.runTask(TaskFactory.java:211)
              at jdk.jshell/jdk.jshell.TaskFactory.parse(TaskFactory.java:145)
              at jdk.jshell/jdk.jshell.TaskFactory.parse(TaskFactory.java:245)
              at jdk.jshell/jdk.jshell.Eval.sourceToSnippets(Eval.java:197)
              at jdk.jshell/jdk.jshell.Eval.eval(Eval.java:133)
              at jdk.jshell/jdk.jshell.JShell.eval(JShell.java:513)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSource(JShellTool.java:3633)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSourceCatchingReset(JShellTool.java:1353)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processInput(JShellTool.java:1251)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.run(JShellTool.java:1222)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.start(JShellTool.java:1005)
              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: com.sun.tools.javac.util.FatalError: Fatal Error: Unable to find method process
              at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:383)
              at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.analyze(TaskFactory.java:417)
              ... 27 more
      Caused by: com.sun.tools.javac.util.FatalError: Fatal Error: Unable to find method process
              at jdk.compiler/com.sun.tools.javac.comp.Resolve.resolveInternalMethod(Resolve.java:2863)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.getProcessMethodType(Attr.java:5019)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitStringTemplate(Attr.java:5003)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCStringTemplate.accept(JCTree.java:2528)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:2490)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1728)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:736)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:755)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1440)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1092)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:736)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1229)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:916)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:736)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5635)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5523)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5347)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5286)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1358)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1331)
              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

      This is because javac tries to look up the process method whether it is present or not.

      Running javac on invalid code also results in a FatalError, but only afterwards:
      $ javac --enable-preview --release 22 Simple2.java
      Simple2.java:3: error: not a processor type: String
              System.out.println(e."\{e}");
                                 ^
      Simple2.java:3: error: cannot find symbol
              System.out.println(e."\{e}");
                                   ^
        symbol: method process(StringTemplate)
        location: class String
      Note: Simple2.java uses preview features of Java SE 22.
      Note: Recompile with -Xlint:preview for details.
      2 errors
      Fatal Error: Unable to find method process

      Code:
      void main() {
              String e = "!";
              System.out.println(e."\{e}");
      }

      I don't know if this should count as a javac bug or a jshell bug, feel free to change accordingly.

            hgreule Hannes Greule
            hgreule Hannes Greule
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: