After version 1.38, putting a ternary as a generic parameter in a function call gives an incorrect error
json.put("id", id == null ? null : id.longValue());
(json and id are both objects of our own types) error over .put:
The method put(String, T) in the type Json is not applicable for the arguments (String, Long)Java(67108979)
lines without a ternary conditional operator, such as below, do not give an error
json.put("id", id.longValue());
I've seen something similar with 1.38 with incorrect compilation errors that don't appear when compiled through javac. A generic type could not be worked out and a default record constructor could not be found.
Reverting to 1.37 appears to have fixed the problem.
i faced same problem with 1.38 and reverting to 1.37 fixed the problem
I have the same problem
it seems it only happens, when the ternary produces two slightly different types and one being a primitive data type?
but both still need to be compatible
the following code has no errors with 1.37
Confirmed both in 1.38.0 (current release) and 1.39.2025011008 (current pre-release):
Reproducible with:
import java.util.function.Supplier;
public class CompileError {
<T> void foo(Supplier<T> p, int foo) {
}
void bar(Integer i) {
foo(null, i != null ? i : 100);
}
}
the problem is not present when using javac as the compiler ("java.jdt.ls.javac.enabled": "on") so probably a problem with ecj? i tried both ecj 4.34 (from end of november) und 4.35M1 (from start of january) ecj 4.34 shows no error while 4.35M1 shows exactly the same error i see in vscode
Same problem, revert to 1.37 fixes
This seems to have been fixed in jdt.core at some point. Latest vscode-java version shows no problem.