Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 521939

Summary: [1.8][inference] Failure to type inference in an "if" statement context
Product: [Eclipse Project] JDT Reporter: Nathaniel Mishkin <mishkin>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED NOT_ECLIPSE QA Contact:
Severity: normal    
Priority: P3 CC: baier, stephan.herrmann
Version: 4.7   
Target Milestone: 4.15 M3   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

Description Nathaniel Mishkin CLA 2017-09-06 10:43:35 EDT
This code:

public class Dummy {
    interface I {
        <T> T m();
    }
    void foo() {
        I i = null;
        boolean x = i.m();
        if (i.m()) {
        }
    }
}

compiles with javac. But on the "if" statement Eclipse reports the error:

Type mismatch: cannot convert from Object to boolean
Comment 1 Stephan Herrmann CLA 2017-09-06 13:29:55 EDT
We probably have a duplicate of this, but I don't have the time right now to search.

The issue here is that JLS does not list this location (condition of an if) among the contexts that allow target typing to influence type inference.

IIRC, javac invents a target type boolean (or Boolean) and illegally uses that during type inference.

Will have another look after Java 9 has sailed. 

Maybe, we can push the spec authors to either update JLS or push the javac team to fix their implementation. IIRC, people were still undecided which direction it should go.
Comment 2 Manoj N Palat CLA 2018-05-17 03:24:19 EDT
bulk move out of 4.8
Comment 3 Manoj N Palat CLA 2018-08-16 00:06:44 EDT
Bulk move out of 4.9
Comment 4 Stephan Herrmann CLA 2018-08-16 05:28:06 EDT
Regarding the "helpwanted" keyword: s.o. would have to ask Oracle (spec author and javac developer) to coordinate which behavior should be right / wrong - see comment 1.
Comment 5 Stephan Herrmann CLA 2020-02-11 10:06:34 EST
*** Bug 560024 has been marked as a duplicate of this bug. ***
Comment 6 Stephan Herrmann CLA 2020-02-11 10:11:07 EST
Here's the JDK bug: https://bugs.openjdk.java.net/browse/JDK-8179483

This has been idle for 3 years, I even pinged them March 2019, to no effect. Hence I won't hold my breath until it is fixed in JLS.

Until they change the spec, ecj is right and javac is wrong in this regard.