Skip to content

Commit 679e485

Browse files
archiecobbsVicente Romero
authored andcommitted
8043251: Bogus javac error: required: no arguments, found: no arguments
Reviewed-by: vromero
1 parent cd10c72 commit 679e485

File tree

6 files changed

+47
-13
lines changed

6 files changed

+47
-13
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4173,17 +4173,34 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
41734173

41744174
Pair<Symbol, JCDiagnostic> c = errCandidate();
41754175
Symbol ws = c.fst.asMemberOf(site, types);
4176-
return diags.create(dkind, log.currentSource(), pos,
4177-
"cant.apply.symbol",
4178-
compactMethodDiags ?
4179-
d -> MethodResolutionDiagHelper.rewrite(diags, pos, log.currentSource(), dkind, c.snd) : null,
4180-
kindName(ws),
4181-
ws.name == names.init ? ws.owner.name : ws.name,
4182-
methodArguments(ws.type.getParameterTypes()),
4183-
methodArguments(argtypes),
4184-
kindName(ws.owner),
4185-
ws.owner.type,
4186-
c.snd);
4176+
4177+
// If the problem is due to type arguments, then the method parameters aren't relevant,
4178+
// so use the error message that omits them to avoid confusion.
4179+
switch (c.snd.getCode()) {
4180+
case "compiler.misc.wrong.number.type.args":
4181+
case "compiler.misc.explicit.param.do.not.conform.to.bounds":
4182+
return diags.create(dkind, log.currentSource(), pos,
4183+
"cant.apply.symbol.noargs",
4184+
compactMethodDiags ?
4185+
d -> MethodResolutionDiagHelper.rewrite(diags, pos, log.currentSource(), dkind, c.snd) : null,
4186+
kindName(ws),
4187+
ws.name == names.init ? ws.owner.name : ws.name,
4188+
kindName(ws.owner),
4189+
ws.owner.type,
4190+
c.snd);
4191+
default:
4192+
return diags.create(dkind, log.currentSource(), pos,
4193+
"cant.apply.symbol",
4194+
compactMethodDiags ?
4195+
d -> MethodResolutionDiagHelper.rewrite(diags, pos, log.currentSource(), dkind, c.snd) : null,
4196+
kindName(ws),
4197+
ws.name == names.init ? ws.owner.name : ws.name,
4198+
methodArguments(ws.type.getParameterTypes()),
4199+
methodArguments(argtypes),
4200+
kindName(ws.owner),
4201+
ws.owner.type,
4202+
c.snd);
4203+
}
41874204
}
41884205

41894206
@Override

src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ compiler.err.switch.expression.no.result.expressions=\
233233
compiler.err.call.must.be.first.stmt.in.ctor=\
234234
call to {0} must be first statement in constructor
235235

236+
# 0: symbol kind, 1: name, 2: symbol kind, 3: type, 4: message segment
237+
compiler.err.cant.apply.symbol.noargs=\
238+
{0} {1} in {2} {3} cannot be applied to given types;\n\
239+
reason: {4}
240+
236241
# 0: symbol kind, 1: name, 2: list of type or message segment, 3: list of type or message segment, 4: symbol kind, 5: type, 6: message segment
237242
compiler.err.cant.apply.symbol=\
238243
{0} {1} in {4} {5} cannot be applied to given types;\n\
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @test /nodynamiccopyright/
3+
* @bug 8043251
4+
* @summary Confusing error message with wrong number of type parameters
5+
* @compile/fail/ref=T8043251.out -XDrawDiagnostics T8043251.java
6+
*/
7+
import java.util.function.Function;
8+
class T8043251 {
9+
Function<String, String> f = Function.<String, String>identity();
10+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
T8043251.java:9:42: compiler.err.cant.apply.symbol.noargs: kindname.method, identity, kindname.interface, java.util.function.Function<T,R>, (compiler.misc.wrong.number.type.args: 1)
2+
1 error

test/langtools/tools/javac/diags/examples/ExplicitParamsDoNotConformToBounds.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* questions.
2222
*/
2323

24-
// key: compiler.err.cant.apply.symbol
24+
// key: compiler.err.cant.apply.symbol.noargs
2525
// key: compiler.misc.explicit.param.do.not.conform.to.bounds
2626

2727
class ExplicitParamsDoNotConformToBounds {

test/langtools/tools/javac/diags/examples/WrongNumberTypeArgsFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* questions.
2222
*/
2323

24-
// key: compiler.err.cant.apply.symbol
24+
// key: compiler.err.cant.apply.symbol.noargs
2525
// key: compiler.misc.wrong.number.type.args
2626

2727
import java.util.*;

0 commit comments

Comments
 (0)