8154374: JShell: setContextClassLoader() for remote Snippet class loader
authorrfield
Mon, 22 Aug 2016 09:12:11 -0700
changeset 40516 9e0e107c39dd
parent 40515 819fc588bd19
child 40517 611ca58fca75
8154374: JShell: setContextClassLoader() for remote Snippet class loader 8080347: jshell tool: /vars when the status is other than Active Reviewed-by: jlahoda
langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DefaultLoaderDelegate.java
langtools/test/jdk/jshell/SimpleRegressionTest.java
langtools/test/jdk/jshell/ToolBasicTest.java
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Mon Aug 22 08:18:18 2016 -0700
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Mon Aug 22 09:12:11 2016 -0700
@@ -1919,7 +1919,7 @@
         {
             String val = state.status(vk) == Status.VALID
                     ? state.varValue(vk)
-                    : "jshell.msg.vars.not.active";
+                    : getResourceString("jshell.msg.vars.not.active");
             hard("  %s %s = %s", vk.typeName(), vk.name(), val);
         });
         return true;
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DefaultLoaderDelegate.java	Mon Aug 22 08:18:18 2016 -0700
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DefaultLoaderDelegate.java	Mon Aug 22 09:12:11 2016 -0700
@@ -77,6 +77,7 @@
 
     public DefaultLoaderDelegate() {
         this.loader = new RemoteClassLoader();
+        Thread.currentThread().setContextClassLoader(loader);
     }
 
     @Override
--- a/langtools/test/jdk/jshell/SimpleRegressionTest.java	Mon Aug 22 08:18:18 2016 -0700
+++ b/langtools/test/jdk/jshell/SimpleRegressionTest.java	Mon Aug 22 09:12:11 2016 -0700
@@ -22,7 +22,7 @@
  */
 
 /*
- * @test 8130450 8158906
+ * @test 8130450 8158906 8154374
  * @summary simple regression test
  * @build KullaTesting TestingInputStream
  * @run testng SimpleRegressionTest
@@ -144,4 +144,9 @@
                 ste(MAIN_SNIPPET, VALID, VALID, false, null),
                 ste(snv, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
     }
+
+    public void testContextClassLoader() {
+        assertEval("class C {}");
+        assertEval("C.class.getClassLoader() == Thread.currentThread().getContextClassLoader()", "true");
+    }
 }
--- a/langtools/test/jdk/jshell/ToolBasicTest.java	Mon Aug 22 08:18:18 2016 -0700
+++ b/langtools/test/jdk/jshell/ToolBasicTest.java	Mon Aug 22 09:12:11 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953
+ * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347
  * @summary Tests for Basic tests for REPL tool
  * @modules jdk.compiler/com.sun.tools.javac.api
  *          jdk.compiler/com.sun.tools.javac.main
@@ -542,6 +542,13 @@
         }
     }
 
+    public void testVarsWithNotActive() {
+        test(
+                a -> assertVariable(a, "Blath", "x"),
+                a -> assertCommandOutputContains(a, "/var -all", "(not-active)")
+        );
+    }
+
     public void testHistoryReference() {
         test(false, new String[]{"-nostartup"},
                 a -> assertCommand(a, "System.err.println(1)", "", "", null, "", "1\n"),