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

Bug 319436

Summary: [1.5][compiler] generic method with multiple types causes compile error
Product: [Eclipse Project] JDT Reporter: Will Horn <will.horn>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Will Horn CLA 2010-07-09 17:26:19 EDT
Build Identifier: 3.6 Helios 20100617-1415

This code does not compile in Eclipse, though javac has no problem with it:


import java.io.Serializable;

public class Test {
  
  public static void main(String[] args) {
    createObject();
  }

  private static <T extends Comparable<?> & Serializable> T createObject() {
    return null;
  }
}

The error is on the invocation of the method:
Bound mismatch: The generic method createObject() of type Test is not applicable for the arguments (). The inferred type Comparable<?> is not a valid substitute for the bounded parameter <T extends Comparable<?> & Serializable>

Reproducible: Always

Steps to Reproduce:
1. Create a java class with the above code
Comment 1 Srikanth Sankaran CLA 2010-07-11 23:19:55 EDT
javac5 does not compile this:

Test.java:6: type parameters of <T>T cannot be determined; no unique maximal ins
tance exists for type variable T with upper bounds java.lang.Object,java.lang.Co
mparable<?>,java.io.Serializable
    createObject();
                ^
1 error

Nor does javac6:

Test.java:6: type parameters of <T>T cannot be determined; no unique maximal ins
tance exists for type variable T with upper bounds java.lang.Object,java.lang.Co
mparable<?>,java.io.Serializable
    createObject();
                ^
[total 313ms]
1 error

Javac7 compiles it alright though.


Will, what version of javac did you try it with ?
Comment 2 Will Horn CLA 2010-07-15 12:36:08 EDT
(In reply to comment #1)
> Will, what version of javac did you try it with ?

Ah, my company uses OpenJDK and this was openjdk6 which is actually a descendent of the sun jdk 7 (http://openjdk.java.net/projects/jdk6/)!

Feel free to close the bug if you don't need to support openjdk6.

The workaround I used was to wrap in a generic type parameterized by T which implemented the multiple interfaces.
Comment 3 Srikanth Sankaran CLA 2010-07-19 10:58:30 EDT
(In reply to comment #2)

> Feel free to close the bug if you don't need to support openjdk6.

It may not be as simple as that, we need to get to understand why
the behavior change occurred at JDK7 and see if eclipse has to
react suitably.

Olivier, Can you help with identifying the earliest JDK7 build
where this code has started compiling ? 

> The workaround I used was to wrap in a generic type parameterized by T which
> implemented the multiple interfaces.

Thanks.
Comment 4 Srikanth Sankaran CLA 2010-08-23 22:20:22 EDT
> Olivier, Can you help with identifying the earliest JDK7 build
> where this code has started compiling ? 

Frederic, since Olivier is away, can you please help
with check ? TIA.
Comment 5 Frederic Fusier CLA 2010-08-24 05:55:38 EDT
(In reply to comment #4)
> > Olivier, Can you help with identifying the earliest JDK7 build
> > where this code has started compiling ? 
> 
> Frederic, since Olivier is away, can you please help
> with check ? TIA.

This code started to compile with build 1.7.0-ea-b32 and it still failed with build 1.7.0-ea-b27. I have no other JDK7 build versions between b27 and b32 to be more precise...
Comment 6 Frederic Fusier CLA 2010-08-24 06:03:55 EDT
(In reply to comment #5)
> (In reply to comment #4)
> > > Olivier, Can you help with identifying the earliest JDK7 build
> > > where this code has started compiling ? 
> > 
> > Frederic, since Olivier is away, can you please help
> > with check ? TIA.
> 
> This code started to compile with build 1.7.0-ea-b32 and it still failed with
> build 1.7.0-ea-b27. I have no other JDK7 build versions between b27 and b32 to
> be more precise...

Sorry, I mixed the version forget my previous comment... :-S

In fact this code started to compile with build 1.7.0-ea-b27 and it failed with build 1.7.0-ea-b25.
Comment 7 Srikanth Sankaran CLA 2011-05-24 12:18:38 EDT
I know what is the problem here, it too late for 3.7, but I'll
include a fix for a subsequent release.
Comment 8 Srikanth Sankaran CLA 2011-05-24 18:54:56 EDT
Closing this bug as a duplicate of bug 341795.
I'll carry over the test case from here into
a junit for that bug.

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