vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

After version 1.38, putting a ternary as a generic parameter in a function call gives an incorrect error

Open DatBrute opened this issue 11 months ago • 6 comments

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());

DatBrute avatar Dec 19 '24 17:12 DatBrute

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.

AndrewDodd42 avatar Jan 03 '25 11:01 AndrewDodd42

i faced same problem with 1.38 and reverting to 1.37 fixed the problem

wangguofeng1923 avatar Jan 06 '25 02:01 wangguofeng1923

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 Image

linuxhelf avatar Jan 09 '25 17:01 linuxhelf

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);
    }

}

phraktle avatar Jan 13 '25 08:01 phraktle

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

Image

linuxhelf avatar Jan 14 '25 20:01 linuxhelf

Same problem, revert to 1.37 fixes

matthewstyler avatar Jan 20 '25 18:01 matthewstyler

This seems to have been fixed in jdt.core at some point. Latest vscode-java version shows no problem.

fbricon avatar Oct 23 '25 11:10 fbricon