1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Tue Oct 15 19:36:45 2013 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Tue Oct 15 21:02:21 2013 +0100 1.3 @@ -2399,13 +2399,28 @@ 1.4 ClashFilter cf = new ClashFilter(site); 1.5 //for each method m1 that is overridden (directly or indirectly) 1.6 //by method 'sym' in 'site'... 1.7 + 1.8 + List<MethodSymbol> potentiallyAmbiguousList = List.nil(); 1.9 + boolean overridesAny = false; 1.10 for (Symbol m1 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) { 1.11 - if (!sym.overrides(m1, site.tsym, types, false)) { 1.12 - checkPotentiallyAmbiguousOverloads(pos, site, sym, (MethodSymbol)m1); 1.13 - continue; 1.14 - } 1.15 - //...check each method m2 that is a member of 'site' 1.16 - for (Symbol m2 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) { 1.17 + if (!sym.overrides(m1, site.tsym, types, false)) { 1.18 + if (m1 == sym) { 1.19 + continue; 1.20 + } 1.21 + 1.22 + if (!overridesAny) { 1.23 + potentiallyAmbiguousList = potentiallyAmbiguousList.prepend((MethodSymbol)m1); 1.24 + } 1.25 + continue; 1.26 + } 1.27 + 1.28 + if (m1 != sym) { 1.29 + overridesAny = true; 1.30 + potentiallyAmbiguousList = List.nil(); 1.31 + } 1.32 + 1.33 + //...check each method m2 that is a member of 'site' 1.34 + for (Symbol m2 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) { 1.35 if (m2 == m1) continue; 1.36 //if (i) the signature of 'sym' is not a subsignature of m1 (seen as 1.37 //a member of 'site') and (ii) m1 has the same erasure as m2, issue an error 1.38 @@ -2424,10 +2439,14 @@ 1.39 } 1.40 } 1.41 } 1.42 + 1.43 + if (!overridesAny) { 1.44 + for (MethodSymbol m: potentiallyAmbiguousList) { 1.45 + checkPotentiallyAmbiguousOverloads(pos, site, sym, m); 1.46 + } 1.47 + } 1.48 } 1.49 1.50 - 1.51 - 1.52 /** Check that all static methods accessible from 'site' are 1.53 * mutually compatible (JLS 8.4.8). 1.54 *