Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DatBrute opened this issue Dec 19, 2024 · 5 comments

Comments

@DatBrute
Copy link

DatBrute commented Dec 19, 2024

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

@AndrewDodd42
Copy link

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.

@wangguofeng1923
Copy link

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

@linuxhelf
Copy link

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

@phraktle
Copy link

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

}

@linuxhelf
Copy link

linuxhelf commented Jan 14, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants