7170058: Confusing error message from javac when overriding a method from a raw supertype

Reviewed-by: mcimadamore
This commit is contained in:
Vicente Romero 2017-06-01 12:51:26 -07:00
parent a449b10079
commit b30409ae05
38 changed files with 86 additions and 72 deletions

View File

@ -1978,10 +1978,9 @@ public class Check {
}
} else if (checkNameClash((ClassSymbol)site.tsym, s1, s2) &&
!checkCommonOverriderIn(s1, s2, site)) {
log.error(pos,
"name.clash.same.erasure.no.override",
s1, s1.location(),
s2, s2.location());
log.error(pos, Errors.NameClashSameErasureNoOverride(
s1.name, types.memberType(site, s1).asMethodType().getParameterTypes(), s1.location(),
s2.name, types.memberType(site, s2).asMethodType().getParameterTypes(), s2.location()));
return s2;
}
}
@ -2465,14 +2464,23 @@ public class Check {
if (!types.isSubSignature(sym.type, types.memberType(site, m2), allowStrictMethodClashCheck) &&
types.hasSameArgs(m2.erasure(types), m1.erasure(types))) {
sym.flags_field |= CLASH;
String key = m1 == sym ?
"name.clash.same.erasure.no.override" :
"name.clash.same.erasure.no.override.1";
log.error(pos,
key,
sym, sym.location(),
m2, m2.location(),
m1, m1.location());
if (m1 == sym) {
log.error(pos, Errors.NameClashSameErasureNoOverride(
m1.name, types.memberType(site, m1).asMethodType().getParameterTypes(), m1.location(),
m2.name, types.memberType(site, m2).asMethodType().getParameterTypes(), m2.location()));
} else {
ClassType ct = (ClassType)site;
String kind = ct.isInterface() ? "interface" : "class";
log.error(pos, Errors.NameClashSameErasureNoOverride1(
kind,
ct.tsym.name,
m1.name,
types.memberType(site, m1).asMethodType().getParameterTypes(),
m1.location(),
m2.name,
types.memberType(site, m2).asMethodType().getParameterTypes(),
m2.location()));
}
return;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 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
@ -30,6 +30,7 @@ import java.util.*;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Attribute.TypeCompound;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind;
@ -377,21 +378,26 @@ public class TransTypes extends TreeTranslator {
MethodSymbol target = bridgeSpan == null ? null : bridgeSpan.snd;
if (target == null || !target.overrides(meth, origin, types, true, false)) {
// Bridge for other symbol pair was added
log.error(pos, "name.clash.same.erasure.no.override",
other, other.location(origin.type, types),
meth, meth.location(origin.type, types));
log.error(pos, Errors.NameClashSameErasureNoOverride(
other.name, types.memberType(origin.type, other).asMethodType().getParameterTypes(),
other.location(origin.type, types),
meth.name, types.memberType(origin.type, meth).asMethodType().getParameterTypes(),
meth.location(origin.type, types)));
}
}
}
} else if (!bridge.overrides(meth, origin, types, true)) {
// Accidental binary override without source override.
// Don't diagnose the problem if it would already
// have been reported in the superclass
if (bridge.owner == origin ||
types.asSuper(bridge.owner.type, meth.owner) == null)
// Don't diagnose the problem if it would already
// have been reported in the superclass
log.error(pos, "name.clash.same.erasure.no.override",
bridge, bridge.location(origin.type, types),
meth, meth.location(origin.type, types));
types.asSuper(bridge.owner.type, meth.owner) == null) {
log.error(pos, Errors.NameClashSameErasureNoOverride(
bridge.name, types.memberType(origin.type, bridge).asMethodType().getParameterTypes(),
bridge.location(origin.type, types),
meth.name, types.memberType(origin.type, meth).asMethodType().getParameterTypes(),
meth.location(origin.type, types)));
}
}
}
}

View File

@ -743,15 +743,15 @@ compiler.err.enums.must.be.static=\
compiler.err.name.clash.same.erasure=\
name clash: {0} and {1} have the same erasure
# 0: symbol, 1: symbol, 2: symbol, 3: symbol, 4: unused, 5: unused
# 0: name, 1: list of type, 2: symbol, 3: name, 4: list of type, 5: symbol
compiler.err.name.clash.same.erasure.no.override=\
name clash: {0} in {1} and {2} in {3} have the same erasure, yet neither overrides the other
name clash: {0}({1}) in {2} and {3}({4}) in {5} have the same erasure, yet neither overrides the other
# 0: symbol, 1: symbol, 2: symbol, 3: symbol, 4: symbol, 5: symbol
# 0: string, 1: name, 2: name, 3: list of type, 4: symbol, 5: name, 6: list of type, 7: symbol
compiler.err.name.clash.same.erasure.no.override.1=\
name clash: {0} in {1} overrides a method whose erasure is the same as another method, yet neither overrides the other\n\
first method: {2} in {3}\n\
second method: {4} in {5}
name clash: {0} {1} has two methods with the same erasure, yet neither overrides the other\n\
first method: {2}({3}) in {4}\n\
second method: {5}({6}) in {7}
# 0: symbol, 1: symbol, 2: symbol, 3: symbol
compiler.err.name.clash.same.erasure.no.hide=\

View File

@ -1,2 +1,2 @@
T6182950b.java:15:16: compiler.err.name.clash.same.erasure.no.override: m(java.util.List<java.lang.Integer>), T6182950b.B, m(java.util.List<java.lang.String>), T6182950b.A, m(java.util.List<java.lang.Integer>), T6182950b.B
T6182950b.java:15:16: compiler.err.name.clash.same.erasure.no.override: m, java.util.List<java.lang.Integer>, T6182950b.B, m, java.util.List<java.lang.String>, T6182950b.A
1 error

View File

@ -1,6 +1,6 @@
/**
* @test /nodynamiccopyright/
* @bug 6476118
* @bug 6476118 7170058
* @summary compiler bug causes runtime ClassCastException for generics overloading
* @compile/fail/ref=T6476118a.out -XDrawDiagnostics T6476118a.java
*/

View File

@ -1,2 +1,2 @@
T6476118a.java:14:20: compiler.err.name.clash.same.erasure.no.override.1: compareTo(T6476118a.B), T6476118a.B, compareTo(java.lang.Object), T6476118a.A, compareTo(T), java.lang.Comparable
T6476118a.java:14:20: compiler.err.name.clash.same.erasure.no.override.1: class, B, compareTo, T6476118a.B, java.lang.Comparable, compareTo, java.lang.Object, T6476118a.A
1 error

View File

@ -1,6 +1,6 @@
/**
* @test /nodynamiccopyright/
* @bug 6476118 6533652
* @bug 6476118 6533652 7170058
* @summary compiler bug causes runtime ClassCastException for generics overloading
* @compile/fail/ref=T6476118b.out -XDrawDiagnostics T6476118b.java
*/

View File

@ -1,2 +1,2 @@
T6476118b.java:12:20: compiler.err.name.clash.same.erasure.no.override.1: compareTo(T6476118b.B), T6476118b.B, compareTo(java.lang.Object), T6476118b, compareTo(T), java.lang.Comparable
T6476118b.java:12:20: compiler.err.name.clash.same.erasure.no.override.1: class, B, compareTo, T6476118b.B, java.lang.Comparable, compareTo, java.lang.Object, T6476118b
1 error

View File

@ -1,6 +1,6 @@
/**
* @test /nodynamiccopyright/
* @bug 6476118
* @bug 6476118 7170058
* @summary compiler bug causes runtime ClassCastException for generics overloading
* @compile/fail/ref=T6476118c.out -XDrawDiagnostics T6476118c.java
*/

View File

@ -1,3 +1,3 @@
T6476118c.java:18:21: compiler.err.name.clash.same.erasure.no.override: foo(java.lang.Object), T6476118c.C, foo(T), T6476118c.A, foo(java.lang.Object), T6476118c.C
T6476118c.java:19:21: compiler.err.name.clash.same.erasure.no.override: foo(java.lang.Number), T6476118c.C, foo(T), T6476118c.B, foo(java.lang.Number), T6476118c.C
T6476118c.java:18:21: compiler.err.name.clash.same.erasure.no.override: foo, java.lang.Object, T6476118c.C, foo, java.lang.Integer, T6476118c.A
T6476118c.java:19:21: compiler.err.name.clash.same.erasure.no.override: foo, java.lang.Number, T6476118c.C, foo, java.lang.Integer, T6476118c.B
2 errors

View File

@ -1,2 +1,2 @@
T6985719a.java:14:5: compiler.err.name.clash.same.erasure.no.override: f(java.util.List<java.lang.Integer>), T6985719a.B, f(java.util.List<java.lang.String>), T6985719a.A
T6985719a.java:14:5: compiler.err.name.clash.same.erasure.no.override: f, java.util.List<java.lang.Integer>, T6985719a.B, f, java.util.List<java.lang.String>, T6985719a.A
1 error

View File

@ -1,2 +1,2 @@
T6985719b.java:14:14: compiler.err.name.clash.same.erasure.no.override: f(java.util.List<java.lang.Integer>), T6985719b.B, f(java.util.List<java.lang.String>), T6985719b.A
T6985719b.java:14:14: compiler.err.name.clash.same.erasure.no.override: f, java.util.List<java.lang.Integer>, T6985719b.B, f, java.util.List<java.lang.String>, T6985719b.A
1 error

View File

@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 6985719
* @bug 6985719 7170058
* @summary Alike methods in interfaces (Inheritance and Overriding)
* @author mcimadamore
* @compile/fail/ref=T6985719c.out -XDrawDiagnostics T6985719c.java

View File

@ -1,2 +1,2 @@
T6985719c.java:14:5: compiler.err.name.clash.same.erasure.no.override: f(java.util.List<X>), T6985719c.B, f(java.util.List<java.lang.String>), T6985719c.A
T6985719c.java:14:5: compiler.err.name.clash.same.erasure.no.override: f, java.util.List<java.lang.Integer>, T6985719c.B, f, java.util.List<java.lang.String>, T6985719c.A
1 error

View File

@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 6985719
* @bug 6985719 7170058
* @summary Alike methods in interfaces (Inheritance and Overriding)
* @author mcimadamore
* @compile/fail/ref=T6985719d.out -XDrawDiagnostics T6985719d.java

View File

@ -1,2 +1,2 @@
T6985719d.java:14:14: compiler.err.name.clash.same.erasure.no.override: f(java.util.List<X>), T6985719d.B, f(java.util.List<java.lang.String>), T6985719d.A
T6985719d.java:14:14: compiler.err.name.clash.same.erasure.no.override: f, java.util.List<java.lang.Integer>, T6985719d.B, f, java.util.List<java.lang.String>, T6985719d.A
1 error

View File

@ -1,2 +1,2 @@
T6985719e.java:13:34: compiler.err.name.clash.same.erasure.no.override: f(java.util.List<java.lang.Integer>), T6985719e.B, f(java.util.List<java.lang.String>), T6985719e.A, f(java.util.List<java.lang.Integer>), T6985719e.B
T6985719e.java:13:34: compiler.err.name.clash.same.erasure.no.override: f, java.util.List<java.lang.Integer>, T6985719e.B, f, java.util.List<java.lang.String>, T6985719e.A
1 error

View File

@ -1,2 +1,2 @@
T6985719f.java:13:39: compiler.err.name.clash.same.erasure.no.override: f(java.util.List<java.lang.Integer>), T6985719f.B, f(java.util.List<java.lang.String>), T6985719f.A, f(java.util.List<java.lang.Integer>), T6985719f.B
T6985719f.java:13:39: compiler.err.name.clash.same.erasure.no.override: f, java.util.List<java.lang.Integer>, T6985719f.B, f, java.util.List<java.lang.String>, T6985719f.A
1 error

View File

@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 6985719
* @bug 6985719 7170058
* @summary Alike methods in interfaces (Inheritance and Overriding)
* @author mcimadamore
* @compile/fail/ref=T6985719g.out -XDrawDiagnostics T6985719g.java

View File

@ -1,2 +1,2 @@
T6985719g.java:13:42: compiler.err.name.clash.same.erasure.no.override: f(java.util.List<java.lang.Integer>), T6985719g.B, f(java.util.List<X>), T6985719g.A, f(java.util.List<java.lang.Integer>), T6985719g.B
T6985719g.java:13:42: compiler.err.name.clash.same.erasure.no.override: f, java.util.List<java.lang.Integer>, T6985719g.B, f, java.util.List<java.lang.String>, T6985719g.A
1 error

View File

@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 6985719
* @bug 6985719 7170058
* @summary Alike methods in interfaces (Inheritance and Overriding)
* @author mcimadamore
* @compile/fail/ref=T6985719h.out -XDrawDiagnostics T6985719h.java

View File

@ -1,2 +1,2 @@
T6985719h.java:13:56: compiler.err.name.clash.same.erasure.no.override: f(java.util.List<java.lang.Integer>), T6985719h.B, f(java.util.List<X>), T6985719h.A, f(java.util.List<java.lang.Integer>), T6985719h.B
T6985719h.java:13:56: compiler.err.name.clash.same.erasure.no.override: f, java.util.List<java.lang.Integer>, T6985719h.B, f, java.util.List<java.lang.String>, T6985719h.A
1 error

View File

@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 7007615
* @bug 7007615 7170058
* @summary java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
* @author mcimadamore
* @compile/fail/ref=T7007615.out -XDrawDiagnostics T7007615.java

View File

@ -1,3 +1,3 @@
T7007615.java:21:14: compiler.err.name.clash.same.erasure.no.override: foo(java.lang.Number), T6985719a.DX, foo(T), T6985719a.AX, foo(java.lang.Number), T6985719a.DX
T7007615.java:22:14: compiler.err.name.clash.same.erasure.no.override: bar(T6985719a.BX<?>), T6985719a.DX, bar(T6985719a.BX), T6985719a.BX, bar(T6985719a.BX<?>), T6985719a.DX
T7007615.java:21:14: compiler.err.name.clash.same.erasure.no.override: foo, java.lang.Number, T6985719a.DX, foo, java.lang.Integer, T6985719a.AX
T7007615.java:22:14: compiler.err.name.clash.same.erasure.no.override: bar, T6985719a.BX<?>, T6985719a.DX, bar, T6985719a.BX, T6985719a.BX
2 errors

View File

@ -1,2 +1,2 @@
T7020657neg.java:22:5: compiler.err.name.clash.same.erasure.no.override: get(java.util.List<java.lang.Integer>), T7020657neg.B, get(java.util.List<java.lang.String>), T7020657neg.A
T7020657neg.java:22:5: compiler.err.name.clash.same.erasure.no.override: get, java.util.List<java.lang.Integer>, T7020657neg.B, get, java.util.List<java.lang.String>, T7020657neg.A
1 error

View File

@ -1,2 +1,2 @@
T7022054neg1.java:15:30: compiler.err.name.clash.same.erasure.no.override: <X>m(X), T7022054neg1.B, m(java.lang.String), T7022054neg1.A, <X>m(X), T7022054neg1.B
T7022054neg1.java:15:30: compiler.err.name.clash.same.erasure.no.override: m, X, T7022054neg1.B, m, java.lang.String, T7022054neg1.A
1 error

View File

@ -1,2 +1,2 @@
T7022054pos1.java:39:25: compiler.err.name.clash.same.erasure.no.override: <X>m(java.lang.String), T7022054pos1.B, m(java.lang.String), T7022054pos1.A, <X>m(java.lang.String), T7022054pos1.B
T7022054pos1.java:39:25: compiler.err.name.clash.same.erasure.no.override: m, java.lang.String, T7022054pos1.B, m, java.lang.String, T7022054pos1.A
1 error

View File

@ -1,3 +1,3 @@
T7034019c.java:18:20: compiler.err.name.clash.same.erasure.no.override: <T>foo(), T7034019c.B, <T>foo(), T7034019c.A
T7034019c.java:18:20: compiler.err.name.clash.same.erasure.no.override: foo, , T7034019c.B, foo, , T7034019c.A
T7034019c.java:20:14: compiler.err.ref.ambiguous: foo, kindname.method, <T>foo(), T7034019c.B, kindname.method, <T>foo(), T7034019c.A
2 errors

View File

@ -1,3 +1,3 @@
T7034019d.java:18:21: compiler.err.name.clash.same.erasure.no.override: <T>foo(), T7034019c.B, <T>foo(), T7034019c.A
T7034019d.java:18:21: compiler.err.name.clash.same.erasure.no.override: foo, , T7034019c.B, foo, , T7034019c.A
T7034019d.java:20:13: compiler.err.ref.ambiguous: foo, kindname.method, <T>foo(), T7034019c.B, kindname.method, <T>foo(), T7034019c.A
2 errors

View File

@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 4951670
* @bug 4951670 7170058
* @summary javac crash with improper overrider
* @author gafter
*

View File

@ -1,2 +1,2 @@
ErasureClashCrash.java:14:16: compiler.err.name.clash.same.erasure.no.override: compareTo(java.lang.Object), ErasureClashCrash, compareTo(T), Compar, compareTo(java.lang.Object), ErasureClashCrash
ErasureClashCrash.java:14:16: compiler.err.name.clash.same.erasure.no.override: compareTo, java.lang.Object, ErasureClashCrash, compareTo, ErasureClashCrash, Compar
1 error

View File

@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 4756416
* @bug 4756416 7170058
* @summary generics: erasure clash not detected
* @author gafter
*

View File

@ -1,3 +1,3 @@
T4757416.java:14:23: compiler.err.name.clash.same.erasure.no.override.1: id(java.lang.String), T4756416.D, id(A), T4756416.I, id(A), T4756416.C
T4757416.java:15:24: compiler.err.name.clash.same.erasure.no.override.1: id(java.lang.Integer), T4756416.D, id(A), T4756416.C, id(A), T4756416.I
T4757416.java:14:23: compiler.err.name.clash.same.erasure.no.override.1: class, D, id, java.lang.String, T4756416.C, id, java.lang.Integer, T4756416.I
T4757416.java:15:24: compiler.err.name.clash.same.erasure.no.override.1: class, D, id, java.lang.Integer, T4756416.I, id, java.lang.String, T4756416.C
2 errors

View File

@ -1,6 +1,6 @@
/**
* @test /nodynamiccopyright/
* @bug 7062745 7157798
* @bug 7062745 7157798 7170058
* @summary Negative test of conflicting same-name methods inherited from multiple interfaces when parameter types not compatible
* @compile/fail/ref=Test4.out -Werror -Xlint:unchecked -XDrawDiagnostics Test4.java
*/

View File

@ -1,6 +1,6 @@
Test4.java:15:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<java.lang.String>), B, m(java.util.Set<java.lang.Integer>), A
Test4.java:17:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<?>), C, m(java.util.Set<java.lang.Integer>), A
Test4.java:23:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<T>), D, m(java.util.Set<java.lang.Integer>), A
Test4.java:25:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<T>), D, m(java.util.Set<?>), C
Test4.java:29:1: compiler.err.name.clash.same.erasure.no.override: <T>m(java.util.Set<T>), E, m(java.util.Set<T>), D
Test4.java:15:1: compiler.err.name.clash.same.erasure.no.override: m, java.util.Set<java.lang.String>, B, m, java.util.Set<java.lang.Integer>, A
Test4.java:17:1: compiler.err.name.clash.same.erasure.no.override: m, java.util.Set<?>, C, m, java.util.Set<java.lang.Integer>, A
Test4.java:23:1: compiler.err.name.clash.same.erasure.no.override: m, java.util.Set<java.lang.Number>, D, m, java.util.Set<java.lang.Integer>, A
Test4.java:25:1: compiler.err.name.clash.same.erasure.no.override: m, java.util.Set<T>, D, m, java.util.Set<?>, C
Test4.java:29:1: compiler.err.name.clash.same.erasure.no.override: m, java.util.Set<T>, E, m, java.util.Set<T>, D
5 errors

View File

@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 8003280
* @bug 8003280 7170058
* @summary Add lambda tests
* This test is for identifying a non-SAM type: Having more than one methods due to inheritance, and none of them has a subsignature of all other methods
* @compile/fail/ref=NonSAM2.out -XDrawDiagnostics NonSAM2.java Helper.java

View File

@ -1,5 +1,5 @@
NonSAM2.java:13:1: compiler.err.types.incompatible.diff.ret: Bar1, Foo1, getAge(java.lang.String)
NonSAM2.java:15:1: compiler.err.name.clash.same.erasure.no.override: getOldest(java.util.List<?>), C, getOldest(java.util.List<java.lang.Number>), A
NonSAM2.java:17:1: compiler.err.name.clash.same.erasure.no.override: getOldest(java.util.List<java.lang.Integer>), D, getOldest(java.util.List<java.lang.Number>), A
NonSAM2.java:21:1: compiler.err.name.clash.same.erasure.no.override: m(S), Bar2, m(T), Foo2
NonSAM2.java:15:1: compiler.err.name.clash.same.erasure.no.override: getOldest, java.util.List<?>, C, getOldest, java.util.List<java.lang.Number>, A
NonSAM2.java:17:1: compiler.err.name.clash.same.erasure.no.override: getOldest, java.util.List<java.lang.Integer>, D, getOldest, java.util.List<java.lang.Number>, A
NonSAM2.java:21:1: compiler.err.name.clash.same.erasure.no.override: m, T2, Bar2, m, T1, Foo2
4 errors

View File

@ -1,2 +1,2 @@
- compiler.err.cant.access: mod.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.module.info.invalid.super.class))
- compiler.err.cant.access: <error>.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.module.name.mismatch: mod/module-info, <error>))
1 error