Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6192945
Votes 3
Synopsis Declaration order of interdependent generic types should not matter
Category java:compiler
Reported Against
Release Fixed 7(b05)
State 10-Fix Delivered, bug
Priority: 5-Very Low
Related Bugs 5052956 , 6499260 , 6556683 , 6569789 , 6747877 , 6804733 , 6193815
Submit Date 09-NOV-2004
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
 customer  Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
Discussed in more detail in the generics forum (http://forum.java.sun.com/thread.jsp?forum=316&thread=566266), this bug relates to the unnecessary restriction of the declaration order of generic types in a class or method. Basically the following class declaration

    public class MyClass<E, D super E>

causes the following compiler errors

    Error:  line (1) > expected
    Error:  line (4) '{' expected

Rewritten in another form, the following declaration

    public class MyClass<E extends D, D>

causes the following compiler error

    Error:  line (1) illegal forward reference

Section 6.3 of the Language Specification says that "type parameters can appear as parts of their own bounds, or as bounds of other type parameters declared in the same section."  The current behaviour appears to contradict this.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attempt to compile either of the two following classes:

public class MyClass<E, D super E> {}

public class MyClass<E extends D, D> {}


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Successful compilation for either form of the class declaration.
ACTUAL -
Compilation failures for both forms of the class declaration.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Compilation of

public class MyClass<E, D super E> {}

yields the following errors

    Error:  line (1) > expected
    Error:  line (4) '{' expected


Compilation of

public class MyClass<E extends D, D> {}

yields the following error

Error:  line (1) illegal forward reference


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Either

public class MyClass<E, D super E> {}

or

public class MyClass<E extends D, D> {}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Current workaround involves swapping the declaration order of the generic types. This can be undesirable, particularly in my case, as the class needs to extend an interface, thus

public class MyClass<D super E, E> implements MyInterface<E, D>

so we have the awkward situation of the the generic types being reversed for the interface and the corresponding class, thus

MyInterface<Integer, Number> obj = new MyClass<Number, Integer>();


Note that there are situations for which there appears to be no such workaround, for example

public class SomeClass<S extends T, T extends SomeInterface<S>> {}
  xxxxx@xxxxx   2004-11-09 20:10:37 GMT
Work Around
N/A
Evaluation
This is two seperate issues:

1. Allowing lower bounds on type variables.
2. Making the declaration order of type variables independent.

ad 1. see RFE 5052956.

ad 2. this is a compiler bug and here is a simple example of what should be allowed:

class Test<D extends E, E> {}

It is not yet clear if there are any restrictions on the use type variables (are cycles OK?) I can't find any restrictions in JLS.

  xxxxx@xxxxx   2004-11-10 01:07:58 GMT

The only (unspecified) restriction is that we cannot have a cycle in the subtype relation.

  xxxxx@xxxxx   2004-11-11 03:53:24 GMT
Comments
  
  Include a link with my name & email   

Submitted On 09-DEC-2005
dcminter
A similar issue, possibly with the same root causes?
http://forum.java.sun.com/thread.jspa?threadID=690363


Submitted On 10-DEC-2005
AlexLamSL
thanks for mentioning my post here - are these Generics-related issues top priority in Mustang? (since they are not conformed to the JLS)


Submitted On 05-SEP-2009
bestam
How can this bug have a so low priority?



PLEASE NOTE: JDK6 is formerly known as Project Mustang