# HG changeset patch # User rfield # Date 1543542329 28800 # Node ID d488477865c013b38e91b9354c808c50652aa17c # Parent 56ca125c973b94ef0b3682b55a5c62f73b947a7f 8213725: JShell NullPointerException due to class file with unexpected package Reviewed-by: jlahoda diff -r 56ca125c973b -r d488477865c0 src/jdk.jshell/share/classes/jdk/jshell/Eval.java --- a/src/jdk.jshell/share/classes/jdk/jshell/Eval.java Thu Nov 29 06:34:46 2018 -0800 +++ b/src/jdk.jshell/share/classes/jdk/jshell/Eval.java Thu Nov 29 17:45:29 2018 -0800 @@ -327,7 +327,7 @@ String initCode = rinit.part(compileSource); ExpressionInfo ei = ExpressionToTypeInfo.localVariableTypeForInitializer(initCode, state, false); - if (ei != null) { + if (ei != null && ei.declareTypeName != null) { typeName = ei.declareTypeName; fullTypeName = ei.fullTypeName; displayType = ei.displayTypeName; diff -r 56ca125c973b -r d488477865c0 test/langtools/jdk/jshell/KullaTesting.java --- a/test/langtools/jdk/jshell/KullaTesting.java Thu Nov 29 06:34:46 2018 -0800 +++ b/test/langtools/jdk/jshell/KullaTesting.java Thu Nov 29 17:45:29 2018 -0800 @@ -737,7 +737,7 @@ expectedSubKind, unressz, othersz); String signature = var.typeName(); assertEquals(signature, expectedTypeName, - "Expected " + var.source() + " to have the name: " + + "Expected " + var.source() + " to have the type name: " + expectedTypeName + ", got: " + signature); } diff -r 56ca125c973b -r d488477865c0 test/langtools/jdk/jshell/VariablesTest.java --- a/test/langtools/jdk/jshell/VariablesTest.java Thu Nov 29 06:34:46 2018 -0800 +++ b/test/langtools/jdk/jshell/VariablesTest.java Thu Nov 29 17:45:29 2018 -0800 @@ -23,7 +23,7 @@ /* * @test - * @bug 8144903 8177466 8191842 8211694 + * @bug 8144903 8177466 8191842 8211694 8213725 * @summary Tests for EvaluationState.variables * @library /tools/lib * @modules jdk.compiler/com.sun.tools.javac.api @@ -492,6 +492,21 @@ assertVarDeclRedefNoInit("String", "s", "\"hi\"", "null"); } + public void badPkgVarDecl() { + Compiler compiler = new Compiler(); + Path nopkgdirpath = Paths.get("cp", "xyz"); + compiler.compile(nopkgdirpath, + "public class TestZ { public static int V = 0; }\n"); + assertDeclareFail("import static xyz.TestZ.V;", + "compiler.err.cant.access"); + + + VarSnippet v1 = varKey(assertEval("var v = xyz.TestZ.V;", IGNORE_VALUE, null, + DiagCheck.DIAG_ERROR, DiagCheck.DIAG_OK, added(RECOVERABLE_NOT_DEFINED))); + assertVariableDeclSnippet(v1, "v", "java.lang.Object", RECOVERABLE_NOT_DEFINED, SubKind.VAR_DECLARATION_WITH_INITIALIZER_SUBKIND, 0, 1); + assertEval("1+1", "2"); + } + private void assertVarDeclRedefNoInit(String typeName, String name, String value, String dvalue) { assertVarDeclRedefNoInit(typeName, name, value, value, dvalue); }