8202157: remove the use of string keys at InapplicableMethodException
Reviewed-by: mcimadamore
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java Tue Apr 10 17:07:21 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java Tue Apr 24 12:20:10 2018 -0700
@@ -138,23 +138,8 @@
List<JCDiagnostic> messages = List.nil();
- InferenceException(JCDiagnostic.Factory diags) {
- super(diags);
- }
-
- @Override
- InapplicableMethodException setMessage() {
- throw new AssertionError("InferenceException is immutable");
- }
-
- @Override
- InapplicableMethodException setMessage(JCDiagnostic diag) {
- throw new AssertionError("InferenceException is immutable");
- }
-
- @Override
- InapplicableMethodException setMessage(String key, Object... args) {
- throw new AssertionError("InferenceException is immutable");
+ InferenceException() {
+ super(null);
}
@Override
@@ -164,7 +149,7 @@
}
InferenceException error(JCDiagnostic diag) {
- InferenceException result = new InferenceException(diags);
+ InferenceException result = new InferenceException();
if (diag != null) {
result.messages = result.messages.append(diag);
}
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Apr 10 17:07:21 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Apr 24 12:20:10 2018 -0700
@@ -143,9 +143,6 @@
checkVarargsAccessAfterResolution =
Feature.POST_APPLICABILITY_VARARGS_ACCESS_CHECK.allowedInSource(source);
polymorphicSignatureScope = WriteableScope.create(syms.noSymbol);
-
- inapplicableMethodException = new InapplicableMethodException(diags);
-
allowModules = Feature.MODULES.allowedInSource(source);
}
@@ -575,7 +572,7 @@
ForAll pmt = (ForAll) mt;
if (typeargtypes.length() != pmt.tvars.length())
// not enough args
- throw inapplicableMethodException.setMessage("wrong.number.type.args", Integer.toString(pmt.tvars.length()));
+ throw new InapplicableMethodException(diags.fragment(Fragments.WrongNumberTypeArgs(Integer.toString(pmt.tvars.length()))));
// Check type arguments are within bounds
List<Type> formals = pmt.tvars;
List<Type> actuals = typeargtypes;
@@ -583,8 +580,9 @@
List<Type> bounds = types.subst(types.getBounds((TypeVar)formals.head),
pmt.tvars, typeargtypes);
for (; bounds.nonEmpty(); bounds = bounds.tail) {
- if (!types.isSubtypeUnchecked(actuals.head, bounds.head, warn))
- throw inapplicableMethodException.setMessage("explicit.param.do.not.conform.to.bounds",actuals.head, bounds);
+ if (!types.isSubtypeUnchecked(actuals.head, bounds.head, warn)) {
+ throw new InapplicableMethodException(diags.fragment(Fragments.ExplicitParamDoNotConformToBounds(actuals.head, bounds)));
+ }
}
formals = formals.tail;
actuals = actuals.tail;
@@ -820,8 +818,7 @@
String key = inferDiag ? diag.inferKey : diag.basicKey;
throw inferDiag ?
infer.error(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args)) :
- inapplicableMethodException
- .setMessage(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args));
+ new InapplicableMethodException(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args));
}
public MethodCheck mostSpecificCheck(List<Type> actuals) {
@@ -1007,7 +1004,7 @@
}
public void report(DiagnosticPosition pos, JCDiagnostic details) {
- throw inapplicableMethodException.setMessage(details);
+ throw new InapplicableMethodException(details);
}
public Warner checkWarner(DiagnosticPosition pos, Type found, Type req) {
@@ -1368,31 +1365,15 @@
private static final long serialVersionUID = 0;
JCDiagnostic diagnostic;
- JCDiagnostic.Factory diags;
-
- InapplicableMethodException(JCDiagnostic.Factory diags) {
- this.diagnostic = null;
- this.diags = diags;
- }
- InapplicableMethodException setMessage() {
- return setMessage((JCDiagnostic)null);
- }
- InapplicableMethodException setMessage(String key) {
- return setMessage(key != null ? diags.fragment(key) : null);
- }
- InapplicableMethodException setMessage(String key, Object... args) {
- return setMessage(key != null ? diags.fragment(key, args) : null);
- }
- InapplicableMethodException setMessage(JCDiagnostic diag) {
+
+ InapplicableMethodException(JCDiagnostic diag) {
this.diagnostic = diag;
- return this;
}
public JCDiagnostic getDiagnostic() {
return diagnostic;
}
}
- private final InapplicableMethodException inapplicableMethodException;
/* ***************************************************************************
* Symbol lookup