JDK-6804733 : javac generates spourious diagnostics for ill-formed type-variable bounds
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: unknown
  • Submitted: 2009-02-12
  • Updated: 2012-01-13
  • Resolved: 2012-01-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b51Fixed
Related Reports
Relates :  
Relates :  
Description
Consider the following source:

import java.util.Collection;
class Test<S extends Runnable> extends ArrayList<S> {
    <T extends S & S> void test() {}
}

when compiling it using JDK 7 compiler you get 3 error messages:

TestX.java:3: cyclic inheritance involving S
    <T extends S & S> void test() {}
     ^
TestX.java:3: a type variable may not be followed by other bounds
    <T extends S & S> void test() {}
                   ^
TestX.java:2: type parameter S is not within its bound
class Test<S extends Runnable> extends ArrayList<S> {
                                                 ^
3 errors

Both the first and the last error messages are wrong: there's no cyclic inheritance involving S - only, T's bound is ill-formed. Moreover it's not true that S is not within its bound (the bound of ArrayList's type parameter is Object!).

This affects netbeans IDE badly - as multiple spourious diagnostics are generated (and NB has to patch javac to obtain the correct behavior)

Comments
SUGGESTED FIX A webrev of this fix is available at the following URL http://hg.openjdk.java.net/jdk7/tl/langtools/rev/84a18d7da478
05-03-2009

EVALUATION The spourious diagnostics come from some work I and Peter have been doing for improving type variable attribution in jdk 7. In particular, Peter's fix (6192945) introduced the erroneous 'cyclic inheritance' error messages, while my fix (6677785) introduced the erroneous 'not within bound' message. The former message is caused by a side-effect in the way in which Check.checkNonCyclic keeps track of already seen type-variables (basically a bound like S & S is seen as cyclic because S is seen twice, which is wrong). The latter message is cause by the fact that cyclic type-variable bounds are attributed with Type.noType which then causes problems with bound checking (as noType is not a subtype of Object). Since S is erroneously seen as cyclic, its type is erroneosly set to Type.noType which then invalidates the bound checking routine.
12-02-2009