Bug 98379 - [1.5][compiler] Type Inference on static method allowed by eclipse, not by javac
Summary: [1.5][compiler] Type Inference on static method allowed by eclipse, not by javac
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 158519 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-06-03 16:48 EDT by Steven Tamm CLA
Modified: 2011-09-27 17:40 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steven Tamm CLA 2005-06-03 16:48:48 EDT
public class BaseObject {
    public <T extends BaseObject> Constructor<T> ctor() {return null;}
    static <T extends BaseObject> T f1() throws Exception{
        return new BaseObject().<T>ctor().newInstance(new Object[0]);
    }
    static <T extends BaseObject> T f2() throws Exception {
        return f1();
    }
}

Eclipse allows f2() line to return without error.

javac 1.5.0_02 returns this error

C:\dev\142\workspace\zreduction>\dev\tools\win32\jdk\jdk1.5.0_02\bin\javac BaseO
bject.java
BaseObject.java:17: type parameters of <T>T cannot be determined; no unique
maximal instance exists for type variable T with upper bounds T,BaseObject
        return f1();

It's fixed if you replace the line with

        return BaseObject.<T>f1();

Not sure if it's an eclipse or a javac bug, but it is a difference.
Comment 1 Philipe Mulet CLA 2005-06-20 10:06:41 EDT
Simpler testcase:
public class X {
    <T extends X> T f1() throws Exception{
    	return null;
    }
    <U extends X> U f2() throws Exception {
        return f1();
    }
}

Inference should realize that <U>f1() is the proper substitute for generic
method. Note that when explicitly qualifying it works well as well.

Closing as javac bug. 
Adding regression test: GenericTypeTest#test765
Comment 2 Philipe Mulet CLA 2006-09-25 09:08:25 EDT
*** Bug 158519 has been marked as a duplicate of this bug. ***
Comment 3 Michael OBrien CLA 2011-09-27 16:40:15 EDT
>Verified reproduced in JDK 1.6.0_21
>Verified fixed in JDK 1.6.0_22 (and 1.6.0_27)
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954
Comment 4 Michael OBrien CLA 2011-09-27 17:40:06 EDT
>	A more systematic test on each release reveals 
	1.6.0_22 = broken (bug with same exception says fixed)
	1.6.0_23 = broken
	1.6.0_24 = broken
	1.6.0_25 = OK
	1.6.0_26 = OK
	1.6.0_27 = OK