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

JShell NullPointerException due to class file with unexpected package

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b23
    • CPU:
      x86_64
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        ADDITIONAL SYSTEM INFORMATION :
        openjdk full version "11+28"

        A DESCRIPTION OF THE PROBLEM :
        When the package of a class file doesn't match with its location on the classpath, a NullPointerException may be thrown.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile a class which is in the default package, but placed inside a subdirectory, e.g. in PowerShell:

        mkdir xyz | Out-Null
        echo "public class Test { public static int V = 0; }" | Out-File xyz/Test.java -Encoding ascii
        javac .\xyz\Test.java

        Then run jshell and execute the following 2 commands:

        import static xyz.Test.V
        var v = xyz.Test.V

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Both commands give an error, but don't let JShell crash
        ACTUAL -
        The first command gives an error:

        | Error:
        | cannot access xyz.Test
        | bad class file: .\xyz\Test.class
        | class file contains wrong class: abc.Test
        | Please remove or make sure it appears in the correct subdirectory of the classpath.
        | import static xyz.Test.V;
        | ^------^
        | Error:
        | static import only from classes and interfaces
        | import static xyz.Test.V;
        | ^-----------------------^

        But the second command crashes JShell with the following exception:

        Exception in thread "main" java.lang.NullPointerException
                at jdk.jshell/jdk.jshell.Eval.processVariables(Eval.java:335)
                at jdk.jshell/jdk.jshell.Eval.lambda$sourceToSnippets$1(Eval.java:215)
                at jdk.jshell/jdk.jshell.TaskFactory.lambda$parse$6(TaskFactory.java:253)
                at jdk.jshell/jdk.jshell.TaskFactory.lambda$runTask$4(TaskFactory.java:213)
                at jdk.compiler/com.sun.tools.javac.api.JavacTaskPool.getTask(JavacTaskPool.java:182)
                at jdk.jshell/jdk.jshell.TaskFactory.runTask(TaskFactory.java:206)
                at jdk.jshell/jdk.jshell.TaskFactory.parse(TaskFactory.java:140)
                at jdk.jshell/jdk.jshell.TaskFactory.parse(TaskFactory.java:238)
                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:493)
                at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSource(JShellTool.java:3547)
                at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSourceCatchingReset(JShellTool.java:1301)
                at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processInput(JShellTool.java:1203)
                at jdk.jshell/jdk.internal.jshell.tool.JShellTool.run(JShellTool.java:1176)
                at jdk.jshell/jdk.internal.jshell.tool.JShellTool.start(JShellTool.java:975)
                at jdk.jshell/jdk.internal.jshell.tool.JShellToolBuilder.start(JShellToolBuilder.java:254)
                at jdk.jshell/jdk.internal.jshell.tool.JShellToolProvider.main(JShellToolProvider.java:120)

        CUSTOMER SUBMITTED WORKAROUND :
        Make sure classes on the classpath are in their correct locations

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                rfield Robert Field
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: