8177847: jshell tool: retain delete of non-retained mode does not locally delete
authorrfield
Mon, 26 Jun 2017 18:43:00 -0700
changeset 45749 11797433fbc0
parent 45748 0202b55d8e08
child 45750 15404afd36ab
8177847: jshell tool: retain delete of non-retained mode does not locally delete Reviewed-by: jlahoda
langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/Feedback.java
langtools/test/jdk/jshell/ToolCommandOptionTest.java
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/Feedback.java	Mon Jun 26 14:16:34 2017 -0700
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/Feedback.java	Mon Jun 26 18:43:00 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1022,7 +1022,9 @@
                     // Note: delete, for safety reasons, does NOT do name matching
                     if (commandOption || quietOption) {
                         errorat("jshell.err.conflicting.options");
-                    } else if (!(retainOption ? retainedMap : modeMap).containsKey(umode)) {
+                    } else if (retainOption
+                            ? !retainedMap.containsKey(umode) && !modeMap.containsKey(umode)
+                            : !modeMap.containsKey(umode)) {
                         // Cannot delete a mode that does not exist
                         errorat("jshell.err.mode.unknown", umode);
                     } else if (omode != null) {
--- a/langtools/test/jdk/jshell/ToolCommandOptionTest.java	Mon Jun 26 14:16:34 2017 -0700
+++ b/langtools/test/jdk/jshell/ToolCommandOptionTest.java	Mon Jun 26 18:43:00 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
  /*
  * @test
- * @bug 8157395 8157393 8157517 8158738 8167128 8163840 8167637 8170368 8172102 8172179
+ * @bug 8157395 8157393 8157517 8158738 8167128 8163840 8167637 8170368 8172102 8172179 8177847
  * @summary Tests of jshell comand options, and undoing operations
  * @modules jdk.jshell/jdk.internal.jshell.tool
  *          jdk.compiler/com.sun.tools.javac.api
@@ -35,6 +35,7 @@
 import java.nio.file.Path;
 import org.testng.annotations.Test;
 import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
 
 @Test
 public class ToolCommandOptionTest extends ReplToolTesting {
@@ -530,4 +531,18 @@
         );
     }
 
+    public void retainModeDeleteLocalTest() {
+        test(
+                (a) -> assertCommand(a, "/set mode rmdlt normal -command",
+                        "|  Created new feedback mode: rmdlt"),
+                (a) -> assertCommand(a, "/set mode rmdlt -delete -retain ",
+                        ""),
+                (a) -> assertCommandCheckOutput(a, "/set feedback",
+                        (s) -> {
+                            assertTrue(s.contains("normal"), "Expected normal mode: " + s);
+                            assertFalse(s.contains("rmdlt"), "Didn't delete rmdlt: " + s);
+                        })
+        );
+    }
+
 }