8199762: JShell API: Failed to detect override when snippet to be overridden has been changed before
authorshinyafox
Sat, 24 Mar 2018 14:43:04 +0900
changeset 49416 f14852315495
parent 49415 56a5f899e882
child 49417 1d3139252c1c
8199762: JShell API: Failed to detect override when snippet to be overridden has been changed before Reviewed-by: rfield
src/jdk.jshell/share/classes/jdk/jshell/MethodSnippet.java
src/jdk.jshell/share/classes/jdk/jshell/Unit.java
test/langtools/jdk/jshell/MethodsTest.java
--- a/src/jdk.jshell/share/classes/jdk/jshell/MethodSnippet.java	Fri Mar 23 17:28:02 2018 -0700
+++ b/src/jdk.jshell/share/classes/jdk/jshell/MethodSnippet.java	Sat Mar 24 14:43:04 2018 +0900
@@ -42,7 +42,7 @@
 public class MethodSnippet extends DeclarationSnippet {
 
     final String signature;
-    private String qualifiedParamaterTypes;
+    private String qualifiedParameterTypes;
 
     MethodSnippet(MethodKey key, String userSource, Wrap guts,
             String name, String signature, Wrap corralled,
@@ -90,10 +90,10 @@
     }
 
     String qualifiedParameterTypes() {
-        return qualifiedParamaterTypes;
+        return qualifiedParameterTypes;
     }
 
-    void setQualifiedParamaterTypes(String sig) {
-        qualifiedParamaterTypes = sig;
+    void setQualifiedParameterTypes(String sig) {
+        qualifiedParameterTypes = sig;
     }
 }
--- a/src/jdk.jshell/share/classes/jdk/jshell/Unit.java	Fri Mar 23 17:28:02 2018 -0700
+++ b/src/jdk.jshell/share/classes/jdk/jshell/Unit.java	Sat Mar 24 14:43:04 2018 +0900
@@ -397,17 +397,14 @@
         if (replaceOldEvent != null) secondaryEvents.add(replaceOldEvent);
 
         // Defined methods can overwrite methods of other (equivalent) snippets
-        if (isNew && si.kind() == Kind.METHOD && status.isDefined()) {
-            MethodSnippet msi = (MethodSnippet)si;
-            String oqpt = msi.qualifiedParameterTypes();
-            String nqpt = computeQualifiedParameterTypes(at, msi);
-            if (!nqpt.equals(oqpt)) {
-                msi.setQualifiedParamaterTypes(nqpt);
-                Status overwrittenStatus = overwriteMatchingMethod(msi);
-                if (overwrittenStatus != null) {
-                    prevStatus = overwrittenStatus;
-                    signatureChanged = true;
-                }
+        if (si.kind() == Kind.METHOD && status.isDefined()) {
+            MethodSnippet msi = (MethodSnippet) si;
+            msi.setQualifiedParameterTypes(
+                    computeQualifiedParameterTypes(at, msi));
+            Status overwrittenStatus = overwriteMatchingMethod(msi);
+            if (overwrittenStatus != null) {
+                prevStatus = overwrittenStatus;
+                signatureChanged = true;
             }
         }
     }
--- a/test/langtools/jdk/jshell/MethodsTest.java	Fri Mar 23 17:28:02 2018 -0700
+++ b/test/langtools/jdk/jshell/MethodsTest.java	Sat Mar 24 14:43:04 2018 +0900
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8080357 8167643 8187359
+ * @bug 8080357 8167643 8187359 8199762
  * @summary Tests for EvaluationState.methods
  * @build KullaTesting TestingInputStream ExpectedDiagnostic
  * @run testng MethodsTest
@@ -199,6 +199,23 @@
         assertActiveKeys();
     }
 
+    // 8199762
+    public void methodsRedeclaration5() {
+        Snippet m1 = methodKey(assertEval("int m(Object o) { return 10; }"));
+        assertMethods(method("(Object)int", "m"));
+
+        Snippet m2 = methodKey(assertEval("int m(Object o) { return 30; }",
+                ste(MAIN_SNIPPET, VALID, VALID, false, null),
+                ste(m1, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
+
+        assertEval("<T> int m(T o) { return 30; }",
+                ste(MAIN_SNIPPET, VALID, VALID, true, null),
+                ste(m2, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
+        assertMethods(method("(T)int", "m"));
+        assertEval("m(null)", "30");
+        assertActiveKeys();
+    }
+
     public void methodsErrors() {
         assertDeclareFail("String f();",
                 new ExpectedDiagnostic("compiler.err.missing.meth.body.or.decl.abstract", 0, 11, 7, -1, -1, Diagnostic.Kind.ERROR));