changeset 49421:f14852315495

8199762: JShell API: Failed to detect override when snippet to be overridden has been changed before Reviewed-by: rfield
author shinyafox
date Sat, 24 Mar 2018 14:43:04 +0900
parents 56a5f899e882
children 1d3139252c1c
files src/jdk.jshell/share/classes/jdk/jshell/MethodSnippet.java src/jdk.jshell/share/classes/jdk/jshell/Unit.java test/langtools/jdk/jshell/MethodsTest.java
diffstat 3 files changed, 30 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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));