changeset 55190:1c291d1c272c

8199623: JShell: corralling not restored on drop Reviewed-by: jlahoda
author rfield
date Mon, 03 Jun 2019 08:21:04 -0700
parents 4ffd6a955e92
children 1cccaaf46c7b
files src/jdk.jshell/share/classes/jdk/jshell/Eval.java test/langtools/jdk/jshell/DropTest.java test/langtools/jdk/jshell/ToolSimpleTest.java
diffstat 3 files changed, 44 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jshell/share/classes/jdk/jshell/Eval.java	Mon Jun 03 07:46:47 2019 -0700
+++ b/src/jdk.jshell/share/classes/jdk/jshell/Eval.java	Mon Jun 03 08:21:04 2019 -0700
@@ -974,7 +974,7 @@
                 ins.stream().forEach(u -> u.setDiagnostics(at));
 
                 // corral any Snippets that need it
-                if (ins.stream().anyMatch(u -> u.corralIfNeeded(ins))) {
+                if (ins.stream().filter(u -> u.corralIfNeeded(ins)).count() > 0) {
                     // if any were corralled, re-analyze everything
                     state.taskFactory.analyze(outerWrapSet(ins), cat -> {
                         ins.stream().forEach(u -> u.setCorralledDiagnostics(cat));
--- a/test/langtools/jdk/jshell/DropTest.java	Mon Jun 03 07:46:47 2019 -0700
+++ b/test/langtools/jdk/jshell/DropTest.java	Mon Jun 03 08:21:04 2019 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8081431 8080069 8167128
+ * @bug 8081431 8080069 8167128 8199623
  * @summary Test of JShell#drop().
  * @build KullaTesting TestingInputStream
  * @run testng DropTest
@@ -31,6 +31,7 @@
 
 import jdk.jshell.DeclarationSnippet;
 import jdk.jshell.Snippet;
+import jdk.jshell.MethodSnippet;
 import jdk.jshell.VarSnippet;
 import org.testng.annotations.Test;
 
@@ -225,4 +226,17 @@
                 ste(MAIN_SNIPPET, VALID, VALID, true, null),
                 ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
     }
+
+    // 8199623
+    public void testTwoForkedDrop() {
+        MethodSnippet p = methodKey(assertEval("void p() throws Exception { ((String) null).toString(); }"));
+        MethodSnippet n = methodKey(assertEval("void n() throws Exception { try { p(); } catch (Exception ex) { throw new RuntimeException(\"bar\", ex); }}"));
+        MethodSnippet m = methodKey(assertEval("void m() { try { n(); } catch (Exception ex) { throw new RuntimeException(\"foo\", ex); }}"));
+        MethodSnippet c = methodKey(assertEval("void c() throws Throwable { p(); }"));
+        assertDrop(p,
+                ste(p, VALID, DROPPED, true, null),
+                ste(n, VALID, RECOVERABLE_DEFINED, false, p),
+                ste(c, VALID, RECOVERABLE_DEFINED, false, p));
+        assertActiveKeys();
+    }
 }
--- a/test/langtools/jdk/jshell/ToolSimpleTest.java	Mon Jun 03 07:46:47 2019 -0700
+++ b/test/langtools/jdk/jshell/ToolSimpleTest.java	Mon Jun 03 08:21:04 2019 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103  8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508 8177466 8172154 8192979 8191842 8198573 8198801 8210596 8210959 8215099
+ * @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103  8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508 8177466 8172154 8192979 8191842 8198573 8198801 8210596 8210959 8215099 8199623
  * @summary Simple jshell tool tests
  * @modules jdk.compiler/com.sun.tools.javac.api
  *          jdk.compiler/com.sun.tools.javac.main
@@ -270,6 +270,33 @@
         );
     }
 
+    // 8199623
+    @Test
+    public void testTwoForkedDrop() {
+        test(
+                (a) -> assertCommand(a, "void p() throws Exception { ((String) null).toString(); }",
+                        "|  created method p()"),
+                (a) -> assertCommand(a, "void n() throws Exception { try { p(); } catch (Exception ex) { throw new IOException(\"bar\", ex); }} ",
+                        "|  created method n()"),
+                (a) -> assertCommand(a, "void m() { try { n(); } catch (Exception ex) { throw new RuntimeException(\"foo\", ex); }}",
+                        "|  created method m()"),
+                (a) -> assertCommand(a, "void c() throws Throwable { p(); }",
+                        "|  created method c()"),
+                (a) -> assertCommand(a, "/drop p",
+                        "|  dropped method p()"),
+                (a) -> assertCommand(a, "m()",
+                        "|  attempted to call method n() which cannot be invoked until method p() is declared"),
+                (a) -> assertCommand(a, "/meth n",
+                        "|    void n()\n" +
+                        "|       which cannot be invoked until method p() is declared"),
+                (a) -> assertCommand(a, "/meth m",
+                        "|    void m()"),
+                (a) -> assertCommand(a, "/meth c",
+                        "|    void c()\n" +
+                                "|       which cannot be invoked until method p() is declared")
+        );
+    }
+
     @Test
     public void testUnknownCommand() {
         test((a) -> assertCommand(a, "/unknown",