JDK-5097387 : can not compile two mutually depending generic interfaces
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-09-06
  • Updated: 2004-09-06
  • Resolved: 2004-09-06
Related Reports
Relates :  
Description

Name: js151677			Date: 09/06/2004


FULL PRODUCT VERSION :
java version "1.5.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-rc-b63)
Java HotSpot(TM) Client VM (build 1.5.0-rc-b63, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
two very simple interfaces, with mutually dependent type parameters do not compile, but should (I expect no problem, but can't compile)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
---- sourcefile 1:
public interface EdgeI<NodeType extends NodeI<EdgeI<NodeType>>> {}
---- sourcefile 2:
public interface NodeI<EdgeType extends EdgeI<NodeI<EdgeType>>> { }
---- end sources


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect no compilation error.
The errormessage "type parameter EdgeI<NodeType> is not within its bound" is wrong, it is within it's bound!
ACTUAL -
C:\Daten\arbeit6\v7>C:\Programme\jdk1.5.0\bin\javac -sourcepath src -d bin -Xlin
t:unchecked src\EdgeI.java
src\EdgeI.java:1: type parameter EdgeI<NodeType> is not within its bound
public interface EdgeI<NodeType extends NodeI<EdgeI<NodeType>>> {}
                                                   ^
src\NodeI.java:1: type parameter NodeI<EdgeType> is not within its bound
public interface NodeI<EdgeType extends EdgeI<NodeI<EdgeType>>> { }
                                                   ^
2 errors

C:\Daten\arbeit6\v7>C:\Programme\jdk1.5.0\bin\javac -sourcepath src -d bin -Xlin
t:unchecked src\NodeI.java
src\NodeI.java:1: type parameter NodeI<EdgeType> is not within its bound
public interface NodeI<EdgeType extends EdgeI<NodeI<EdgeType>>> { }
                                                   ^
src\EdgeI.java:1: type parameter EdgeI<NodeType> is not within its bound
public interface EdgeI<NodeType extends NodeI<EdgeI<NodeType>>> {}
                                                   ^
2 errors

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
see Steps to Reproduce
---------- END SOURCE ----------
(Incident Review ID: 301989) 
======================================================================

Comments
EVALUATION This is not a bug. E.g., one of the error messages say that in: interface EdgeI<NodeType extends NodeI<EdgeI<NodeType>>> EdgeI<NodeType> is not within its bound. Why is that? The bound is found in the second declaration: interface NodeI<EdgeType extends EdgeI<NodeI<EdgeType>>> This say that the bound of the type variable EdgeType is EdgeI<NodeI<EdgeType>>. This mean that EdgeI<NodeType> must be a subtype of EdgeI<NodeI<EdgeType>>. Most people's intuition would say this is true if only NodeType is a subtype of NodeI<EdgeType> (this is how it would have been if we were talking about arrays). However, as it is explained in the Generics Tutorial by Bracha (http://java.sun.com/j2se/5/pdf/generics-tutorial.pdf) this is not the case. Instead the requirement is that the types must be the same and NodeType is not the same type as NodeI<EdgeType>. Now enter wildcards which relaxes the rules by imposing a "read-only" or "write-only" view on generic types: interface EdgeI<NodeType extends NodeI<? extends EdgeI<NodeType>>> {} interface NodeI<EdgeType extends EdgeI<? extends NodeI<EdgeType>>> {} But see bug 5097548. ###@###.### 2004-09-06
06-09-2004