1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Sat Sep 18 09:54:51 2010 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Sat Sep 18 09:56:23 2010 -0700 1.3 @@ -80,25 +80,12 @@ 1.4 1.5 } 1.6 1.7 - public static class InferenceException extends RuntimeException { 1.8 + public static class InferenceException extends Resolve.InapplicableMethodException { 1.9 private static final long serialVersionUID = 0; 1.10 1.11 - JCDiagnostic diagnostic; 1.12 - JCDiagnostic.Factory diags; 1.13 - 1.14 InferenceException(JCDiagnostic.Factory diags) { 1.15 - this.diagnostic = null; 1.16 - this.diags = diags; 1.17 + super(diags); 1.18 } 1.19 - 1.20 - InferenceException setMessage(String key, Object... args) { 1.21 - this.diagnostic = diags.fragment(key, args); 1.22 - return this; 1.23 - } 1.24 - 1.25 - public JCDiagnostic getDiagnostic() { 1.26 - return diagnostic; 1.27 - } 1.28 } 1.29 1.30 public static class NoInstanceException extends InferenceException { 1.31 @@ -320,7 +307,7 @@ 1.32 Type qtype1 = types.subst(that.qtype, that.tvars, undetvars); 1.33 if (!types.isSubtype(qtype1, to)) { 1.34 throw unambiguousNoInstanceException 1.35 - .setMessage("no.conforming.instance.exists", 1.36 + .setMessage("infer.no.conforming.instance.exists", 1.37 that.tvars, that.qtype, to); 1.38 } 1.39 for (List<Type> l = undetvars; l.nonEmpty(); l = l.tail) 1.40 @@ -378,6 +365,11 @@ 1.41 // instantiate all polymorphic argument types and 1.42 // set up lower bounds constraints for undetvars 1.43 Type varargsFormal = useVarargs ? formals.last() : null; 1.44 + if (varargsFormal == null && 1.45 + actuals.size() != formals.size()) { 1.46 + throw unambiguousNoInstanceException 1.47 + .setMessage("infer.arg.length.mismatch"); 1.48 + } 1.49 while (actuals.nonEmpty() && formals.head != varargsFormal) { 1.50 Type formal = formals.head; 1.51 Type actual = actuals.head.baseType(); 1.52 @@ -390,19 +382,16 @@ 1.53 : types.isSubtypeUnchecked(actual, undetFormal, warn); 1.54 if (!works) { 1.55 throw unambiguousNoInstanceException 1.56 - .setMessage("no.conforming.assignment.exists", 1.57 + .setMessage("infer.no.conforming.assignment.exists", 1.58 tvars, actualNoCapture, formal); 1.59 } 1.60 formals = formals.tail; 1.61 actuals = actuals.tail; 1.62 actualsNoCapture = actualsNoCapture.tail; 1.63 } 1.64 - if (formals.head != varargsFormal || // not enough args 1.65 - !useVarargs && actuals.nonEmpty()) { // too many args 1.66 - // argument lists differ in length 1.67 - throw unambiguousNoInstanceException 1.68 - .setMessage("arg.length.mismatch"); 1.69 - } 1.70 + 1.71 + if (formals.head != varargsFormal) // not enough args 1.72 + throw unambiguousNoInstanceException.setMessage("infer.arg.length.mismatch"); 1.73 1.74 // for varargs arguments as well 1.75 if (useVarargs) { 1.76 @@ -416,7 +405,7 @@ 1.77 boolean works = types.isConvertible(actual, elemUndet, warn); 1.78 if (!works) { 1.79 throw unambiguousNoInstanceException 1.80 - .setMessage("no.conforming.assignment.exists", 1.81 + .setMessage("infer.no.conforming.assignment.exists", 1.82 tvars, actualNoCapture, elemType); 1.83 } 1.84 actuals = actuals.tail;