Skip to content

Fix unchecked conversion not failed compilation#4961

Open
chrisrueger wants to merge 1 commit into
eclipse-jdt:masterfrom
chrisrueger:fix-gh4957
Open

Fix unchecked conversion not failed compilation#4961
chrisrueger wants to merge 1 commit into
eclipse-jdt:masterfrom
chrisrueger:fix-gh4957

Conversation

@chrisrueger
Copy link
Copy Markdown

@chrisrueger chrisrueger commented Mar 20, 2026

Closes #4957

What it does

How to test

  • run org.eclipse.jdt.core.tests.compiler.regression.GenericsRegressionTest_9.testGH4957() without the fix in org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.computeCompatibleMethod(MethodBinding, TypeBinding[], Scope, InvocationSite)

or just use e.g. Eclipse 2025-03 (or even 2026-06 (4.40) Build id: I20260319-1800 master) and paste the the following class:

import java.util.Comparator;
import java.util.Map;

public class Snippet {

    public static void main(String[] args) {

        Comparator<Map<String, Object>> eventComparator = Comparator
            .<Map<String, Object>, Comparable>comparing(e -> (Comparable) e.get("event_date"),
                Comparator.nullsLast(Comparator.naturalOrder()))
            .thenComparing(e -> (String) e.get("event_type"));
    }

}

Expected Result: Compilation should fail in Eclipse
Actual result: Compiliation succeeds.

But in javacc compilation fails.

With this PR compilation fails also in Eclipse.

But note: Eclipse seems to error with a different message than javac. Not sure this is a deeper problem. But at least it fails at the same place.

ECJ fails with:

"5. ERROR in Snippet.java (at line 11)\n" +
			"	.thenComparing(e -> (String) e.get(\"event_type\"));\n" +
			"	                               ^^^\n" +
			"The method get(String) is undefined for the type Object\n" +

while javac failed with:

Snippet.java:13: error: cannot find symbol
            .thenComparing(e -> (String) e.get("event_type"));
                                          ^
  symbol:   method get(String)
  location: variable e of type Object
Snippet.java:13: warning: [unchecked] unchecked conversion
            .thenComparing(e -> (String) e.get("event_type"));
                          ^
  required: Comparator<Map<String,Object>>
  found:    Comparator
1 error
5 warnings
error: compilation failed

Disclaimer:

I used AI to help me understand the issue and spec and find the places in the code. I have manually tested and debugged via latest JDT Dev environment via Oomph and ran my test in Eclipse.
This is my first step in the compiler space. Feel free to reject it or just use it as a base for a better fix if needed.

Author checklist

Detect when any explicit type argument is a raw type
Adds regression test testGH4957 reproducing the Comparator.comparing + raw Comparable scenario (issue eclipse-jdt#4957) and asserting the expected warnings/errors.
With this fix testGH4957 passes.
@venkateshkona3456-oss
Copy link
Copy Markdown

Hello,
I would like to work on this issue. Is it available?

Thank you!

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

Successfully merging this pull request may close these issues.

Eclipse 2026-03 compiles fine but Java does not: unchecked conversion

2 participants