JDK-6199662 : javac: compilation success depends on compilation order
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-11-23
  • Updated: 2010-05-10
  • Resolved: 2005-09-30
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 6
6 b55Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
Below are three files: TreeInfo.java, TreeScanner.java and Tree.java.
If they are compiled with
	javac p/Tree.java p/TreeScanner.java p/TreeInfo.java
the compilation succeeds.

If they are compiled with 
	javac p/TreeInfo.java p/TreeScanner.java p/Tree.java
you get the following error:

p/TreeScanner.java:9: unreported exception java.lang.Throwable; must be caught or declared to be thrown
	if(tree!=null) tree.accept(this);
                                  ^
1 error



------Tree.java--------------
package p;

public abstract class Tree {

    /** Visit this tree with a given visitor.
     */
    public abstract <E extends Throwable> void accept(Visitor<E> v) throws E;


    /** A generic visitor class for trees.
     */
    public static abstract class Visitor<E extends Throwable> {
	public void visitTree(Tree that)                   throws E { assert false; }
    }
}


------TreeInfo.java----------
package p;
import p.Tree.*;

public class TreeInfo {

    public static void declarationFor(final Tree tree) {
	class DeclScanner extends TreeScanner<Error> {
            public void scan(Tree tree) {
            }
	}
	DeclScanner s = new DeclScanner();
	tree.accept(s);
    }
}


------TreeScanner.java-------
package p;
import p.Tree.*;

public class TreeScanner<E extends Throwable> extends Visitor<E> {

    /** Visitor method: Scan a single node.
     */
    public void scan(Tree tree) throws E {
	if(tree!=null) tree.accept(this);
    }
}

Comments
EVALUATION The problem is apparently that attribution and flow analysis is mixed with erasure in main.JavaCompiler.compile in the while(todo.nonEmpty()) loop. The work should be split into two: first a loop to do attribution and flow analysis, then a loop to translate the types. This analysis is confirmed by disabling the second part of the loop. ###@###.### 2004-11-24 08:24:54 GMT A more correct solution would be to make erasure "non-destructive". ###@###.### 2005-05-18 02:16:13 GMT Extracted "flow" phase out of "desugar" ###@###.### 2005-06-23 23:23:49 GMT
24-11-2004