Community
Participate
Working Groups
Build ID: M20090211-1700 Steps To Reproduce: Here is the demo code: interface DataI<T> extends Comparable<DataI<? extends T>>{} interface ServiceI { public <D extends DataI> D find(DataI<? super D> dataID) throws Exception; public <D extends DataI<? super D>> D find(Class<D> type, String key) throws Exception; } public class EBug implements ServiceI { public <D extends DataI> D find(DataI<? super D> dataID) throws Exception { return null; } public <D extends DataI<? super D>> D find(Class<D> type, String key) throws Exception { DataI<D> id = null; DataI<D> retVal = find(id); return null; } } This code can be compiled using javac, but it shows this compilation error: Type mismatch: cannot convert from D to DataI<D> in the IDE. This prevents the project from compilation and debugging from the IDE. I know I can change the code to make the error gone in IDE, but our projects have lots of generics code. There are other generics errors in IDE as well. This makes it impossible for us to use Eclipse IDE for our team. More information:
We are consistent with javac on the error in type X, but not with type Y : interface I<T> {} class X { <D extends I<D>> D find(I<? super D> ID) { return null; } <D extends I<? super D>> void test(I<D> id) { // incompatible types; inferred type argument(s) I<D> do not conform to // bounds of type variable(s) D - required: I<D> found: <D>D I<D> retVal = find(id); } } class Y { <D extends I> D find(I<? super D> ID) { return null; } <D extends I<? super D>> void test(I<D> id) { I<D> retVal = find(id); // javac has no error, we find the same error as X } }
Philippe - please take a look & tell me if this makes sense to you. I think this is a javac bug. - D1 is inferred to be D2 so find() returns D2 - you cannot assign D2 into I<D2>, as test2 shows, so why can you when its the return type of find() ? interface I<T> {} class Y { <D1 extends I> D1 find(I<? super D1> ID) { return null; } <D2 extends I<? super D2>> void test(I<D2> id) { I<D2> retVal = find(id); // javac has no error, we cannot convert D2 to I<D2> } <D2 extends I<? super D2>> void test2(D2 d2) { I<D2> d = d2; // javac has same error as us, cannot convert D2 to I<D2> } }
Targetting 3.6. If a fix is found in time for 3.5.2, we might backport it.
> interface DataI<T> extends Comparable<DataI<? extends T>>{} > > interface ServiceI > { > public <D extends DataI> D find(DataI<? super D> dataID) throws Exception; > public <D extends DataI<? super D>> D find(Class<D> type, String key) > throws Exception; > } > > public class EBug implements ServiceI > { > public <D extends DataI> D find(DataI<? super D> dataID) throws Exception > { > return null; > } > > public <D extends DataI<? super D>> D find(Class<D> type, String key) > throws Exception > { > DataI<D> id = null; > DataI<D> retVal = find(id); > return null; > } > } Please note that this test fails to compile with javac 7b77 EBug.java:21: incompatible types DataI<D> retVal = find(id); ^ required: DataI<D> found: INT#1 where D is a type-variable: D extends DataI<? super D> declared in method <D>find(Class<D>,String) where INT#1 is an intersection type: INT#1 extends D,DataI<D> 1 error.
The code snippets in comment#0 comment#1, comment#2 all fail to compile with javac 7b77 with every errorneous line as flagged by eclipse also being flagged so by javac. Frederic, can I request you to to find the earliest version of javac 7bxx where this behavior convergence has come about, so I can track it to a javac defect ? -- Thanks! Removing the blocker status as this is very likely a javac defect fixed in the 7x stream.
(In reply to comment #5) > > Frederic, can I request you to to find the earliest version > of javac 7bxx where this behavior convergence has come about, > so I can track it to a javac defect ? -- Thanks! > Sure, I'll look for it tomorrow morning...
(In reply to comment #5) > The code snippets in comment#0 comment#1, comment#2 > all fail to compile with javac 7b77 with every errorneous > line as flagged by eclipse also being flagged so by javac. On comment 0, javac 1.7b91 reports: X.java:20: incompatible types DataI<D> retVal = find(id); ^ required: DataI<D> found: INT#1 where D is a type-variable: D extends DataI<? super D> declared in method <D>find(Class<D>,String) where INT#1 is an intersection type: INT#1 extends D,DataI<D> 1 error On comment 2, same javac reports: `X.java:9: invalid inferred types for D#1; inferred type does not conform to declared bound(s) I<D> retVal = find(id); ^ inferred: INT#1 bound(s): I<INT#1> where D#1,D#2 are type-variables: D#1 extends I<D#1> declared in method <D#1>find(I<? super D#1>) D#2 extends I<? super D#2> declared in method <D#2>test(I<D#2>) where INT#1 is an intersection type: INT#1 extends D#2,I<D#2> X.java:17: incompatible types I<D> retVal = find(id); // javac has no error, we find the same error as X ^ required: I<D> found: INT#1 where D is a type-variable: D extends I<? super D> declared in method <D>test(I<D>) where INT#1 is an intersection type: INT#1 extends D,I<D> 2 errors On comment 2, X.java:6: incompatible types I<D2> retVal = find(id); // javac has no error, we cannot convert D2 to I<D2> ^ required: I<D2> found: INT#1 where D2 is a type-variable: D2 extends I<? super D2> declared in method <D2>test(I<D2>) where INT#1 is an intersection type: INT#1 extends D2,I<D2> X.java:9: incompatible types I<D2> d = d2; // javac has same error as us, cannot convert D2 to I<D2> ^ required: I<D2> found: D2 where D2 is a type-variable: D2 extends I<? super D2> declared in method <D2>test2(D2) 2 errors All of these errors are consistent with Eclipse errors.
(In reply to comment #7) > (In reply to comment #5) > > The code snippets in comment#0 comment#1, comment#2 > > all fail to compile with javac 7b77 with every errorneous > > line as flagged by eclipse also being flagged so by javac. > On comment 0, javac 1.7b91 reports: > ... > On comment 2, same javac reports: > ... I tried with the different jdk 1.7 version I have on my machine and the result is that javac did not report those errors using 1.7 b61 and below. The first 1.7 version to report them is 1.7 b65. Unfortunately, I haven't versions b62 to b64, hence I cannot be more precise... :-S
(In reply to comment #8) > (In reply to comment #7) > > (In reply to comment #5) > > > The code snippets in comment#0 comment#1, comment#2 > > > all fail to compile with javac 7b77 with every errorneous > > > line as flagged by eclipse also being flagged so by javac. > > On comment 0, javac 1.7b91 reports: > > ... > > On comment 2, same javac reports: > > ... > > I tried with the different jdk 1.7 version I have on my machine and the result > is that javac did not report those errors using 1.7 b61 and below. The first > 1.7 version to report them is 1.7 b65. Unfortunately, I haven't versions b62 to > b64, hence I cannot be more precise... :-S Thanks Frederic, it is close enough. I believe the javac defect is http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6638712 where the notes also call out that eclipse behaves correctly. Olivier, thanks for checking with 7b91. Closing as INVALID.
Verified for 3.6RC1.