Bug 326067 - Bound mismatch on unused generic method parameters
Summary: Bound mismatch on unused generic method parameters
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.8 M4   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-23 10:56 EDT by picture.cooking CLA
Modified: 2011-12-06 05:55 EST (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 picture.cooking CLA 2010-09-23 10:56:50 EDT
Build Identifier: 20100617-1415

The method <fails> in the following does not compile, resulting in "Bound mismatch: The generic method fails(E) of type ServiceUtils is not applicable for the arguments (OwnedEntity<Integer,Entity<Integer>>). The inferred type Entity<Integer> is not a valid substitute for the bounded parameter <O extends Entity<L>>"

Whereas the method <works> does.  Both compile under javac

public class Service
{
    
    public void fails(OwnedEntity<Integer, Entity<Integer>> entity) {
        ServiceUtils.fails(entity);        
    }

    public void works(OwnedEntity<Integer, Entity<Integer>> entity, Integer dummy) {
        ServiceUtils.works(entity, dummy);        
    }

}

public class Entity<K extends Serializable>
{
    K key;
}

public class OwnedEntity<K extends Serializable, O extends Entity<? extends Serializable>> extends Entity<K>
{
    O owner;
}

public class ServiceUtils
{

    public static <E extends OwnedEntity<K, O>, K extends Serializable, O extends Entity<L>, L extends Serializable> void fails(
            E entity)
    {
    }

    public static <E extends OwnedEntity<K, O>, K extends Serializable, O extends Entity<L>, L extends Serializable> void works(
            E entity, L dummy)
    {
    }

}




Reproducible: Always

Steps to Reproduce:
1. Attempt to compile
Comment 1 Olivier Thomann CLA 2010-09-23 11:11:03 EDT
Srikanth, please investigate.
Comment 2 Srikanth Sankaran CLA 2011-11-21 05:17:04 EST
See that this code does not compile with JDK7.

javac 7b147 complains: 

X.java:7: error: invalid inferred types for K,O,L; inferred type does not confor
m to declared bound(s)
        ServiceUtils.fails(entity);
                          ^
    inferred: Entity<Integer>
    bound(s): Entity<Serializable>
  where K,E,O,L are type-variables:
    K extends Serializable declared in method <E,K,O,L>fails(E)
    E extends OwnedEntity<K,O> declared in method <E,K,O,L>fails(E)
    O extends Entity<L> declared in method <E,K,O,L>fails(E)
    L extends Serializable declared in method <E,K,O,L>fails(E)
1 error

While eclipse complains:

Bound mismatch: The generic method fails(E) of type ServiceUtils is not applicable for the arguments (OwnedEntity<Integer,Entity<Integer>>). The inferred 
 type Entity<Integer> is not a valid substitute for the bounded parameter <O extends Entity<L>>

against the simplified test case below which can be cut & pasted into a single
file:

//---------------------------------------------------
import java.io.Serializable;
public class X {
    public void fails(OwnedEntity<Integer, Entity<Integer>> entity) {
        ServiceUtils.fails(entity);        
    }
    public void works(OwnedEntity<Integer, Entity<Integer>> entity, Integer dummy) {
        ServiceUtils.works(entity, dummy);        
    }
}
class Entity<K extends Serializable> {
    K key;
}
class OwnedEntity<K extends Serializable, O extends Entity<? extends Serializable>> extends Entity<K> {
    O owner;
}
class ServiceUtils {

    public static <E extends OwnedEntity<K, O>, K extends Serializable, O extends Entity<L>, L extends Serializable> void fails(
            E entity) {
    }

    public static <E extends OwnedEntity<K, O>, K extends Serializable, O extends Entity<L>, L extends Serializable> void works(
            E entity, L dummy) {
    }
}
// ---------------------------------------------------------------

Since eclipse behavior matches the latest javac behavior, I conclude
that this was a bug in JDK5,6 compilers which has since been fixed.

Closing this as INVALID.
Comment 3 Jay Arthanareeswaran CLA 2011-12-06 05:55:44 EST
Verified for 3.8M4