-
Bug
-
Resolution: Fixed
-
P3
-
10, 11, 12
-
b23
-
x86_64
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8265471 | 11.0.13-oracle | Adam Sotona | P3 | Closed | Duplicate | |
JDK-8265532 | 11.0.12-oracle | Adam Sotona | P3 | Resolved | Fixed | b02 |
JDK-8263657 | 11.0.12 | Robert Field | P3 | Resolved | Fixed | b01 |
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
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
- backported by
-
JDK-8263657 JShell NullPointerException due to class file with unexpected package
-
- Resolved
-
-
JDK-8265532 JShell NullPointerException due to class file with unexpected package
-
- Resolved
-
-
JDK-8265471 JShell NullPointerException due to class file with unexpected package
-
- Closed
-