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

Bug 445222

Summary: [1.8][compiler][null] "Cannot infer type argument" but only with Null Analysis enabled
Product: [Eclipse Project] JDT Reporter: Clovis Seragiotto <clovis.seragiotto>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: srikanth_sankaran
Version: 4.4   
Target Milestone: 4.5 M1   
Hardware: PC   
OS: Windows NT   
Whiteboard:

Description Clovis Seragiotto CLA 2014-09-26 14:45:49 EDT
The following program can be compiled with Null Analysis disabled. With Null Analysis enabled, one gets the error "Cannot infer type arguments for Foo<>" at line 6. (Perhaps one or more @Nullable/@NonNull are missing, but the error message gives no hint where).

package foobar;

@org.eclipse.jdt.annotation.NonNullByDefault
class Bar<E> {
    static <T> Foo<T> x(T element) {
        return new Foo<>(element);
    }

    public static class Foo<T> {
        T t;
        Foo(T t) { this.t = t; }
    }
}
Comment 1 Clovis Seragiotto CLA 2014-09-26 14:51:58 EDT
Note: no error is issued if I use a factory method intead of new Foo<>(element)
 
static <T> Foo<T> x(T element) {
    return newFoo(element);
}

static <T> Foo<T> newFoo(T element) {
    throw new UnsupportedOperationException();
}
Comment 2 Clovis Seragiotto CLA 2014-09-27 17:17:58 EDT
Build id: 20140925-1800
JDK Compliance: JavaSE-1.8
Comment 3 Stephan Herrmann CLA 2015-05-12 14:13:24 EDT
I can reproduce with 4.4.x but not after bug 440759 was fixed.

This is not a perfect match, but that's all I can see now.

Please re-open if the problem can be observed with recent builds (e.g., 4.5M1 or later).

*** This bug has been marked as a duplicate of bug 440759 ***