JDK-6197005 : Partial subst broken
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic
  • CPU: generic
  • Submitted: 2004-11-18
  • Updated: 2010-04-02
  • Resolved: 2006-09-30
Related Reports
Relates :  
Description
$ cat -n Subst.java
     1  class A<T> {
     2      class B {
     3          T returnT() { return null; }
     4          Object returnU() { return null; }
     5      }
     6  }
$ cat -n Subst2.java
     1  class A<T> {
     2      class B<U> {
     3          T returnT() { return null; }
     4          U returnU() { return null; }
     5      }
     6  }
$ cat -n X.java
     1  class X {
     2      A<String>.B y;
     3  }
$ cat -n Y.java
     1  class Y {
     2      X x;
     3      void foo() {
     4          String s = x.y.returnU();
     5      }
     6      public static void main(String... args) {
     7      }
     8  }

Now compile like this:

$ rm *.class
$ javac -sourcepath /xyyz Subst.java X.java Y.java
Y.java:4: incompatible types
found   : java.lang.Object
required: java.lang.String
        String s = x.y.returnU();
                              ^
1 error
$ javac -sourcepath /xyyz Subst2.java Y.java

The last command succeeds indicating that the type variable U got the type String.

###@###.### 2004-11-18 05:34:50 GMT

Comments
EVALUATION This was eventually fixed as a side effect of 6356636.
30-09-2006

EVALUATION No, the proposed fix for 6356636 which addressed this issue turned out to be problematic.
23-02-2006

EVALUATION This will be fixed as part of 6356636.
06-01-2006

SUGGESTED FIX ###@###.### 2004-11-19 03:23:58 GMT
18-11-2004

EVALUATION I can see three solutions to this problem: 1. Have javac recheck class files when loading them 2. Check (lazily) for the problematic situation in subst 3. Treat the problematic declaration as a raw type The first option is very unlikely as we normally trust classfiles to be valid. The second option is easy to implement, but it will be hard to give a good diagnostic. It is not clear how to implement the third option, however that may be the only valid solution satisfying binary compatibility. ###@###.### 2004-11-18 05:46:48 GMT I have a solution for option three but must ensure that this follows the specification. ###@###.### 2004-11-18 08:49:18 GMT It turned out that my solution wasn't entirely correct. ###@###.### 2004-11-19 03:23:57 GMT
18-11-2004