Compiling Javac
I downloaded the javac sources and gave them a whirl with ant on my PowerBook. No success. They wouldn’t compile. I’m not sure whether this is because I’m using a Mac or because I’m using Java 5, and they want Java 6. There seem to be several missing or incompatible classes.
~/projects/compiler$ ant Buildfile: build.xml prep: [mkdir] Created dir: /Users/elharo/Projects/compiler/build/bootclasses [mkdir] Created dir: /Users/elharo/Projects/compiler/build/classes [mkdir] Created dir: /Users/elharo/Projects/compiler/dist/bin [mkdir] Created dir: /Users/elharo/Projects/compiler/dist/lib check-javac.isuptodate: build-lib.javac.jar: [mkdir] Created dir: /Users/elharo/Projects/compiler/build/gensrc/com/sun/tools/javac [copy] Copying 1 file to /Users/elharo/Projects/compiler/build/gensrc/com/sun/tools/javac/resources [javac] Compiling 250 source files to /Users/elharo/Projects/compiler/build/bootclasses [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:84: interface expected here [javac] public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1793: cannot find symbol [javac] symbol : class Kind [javac] location: class com.sun.tools.javac.tree.JCTree.TypeBoundKind [javac] public Kind getKind() { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java:449: reference to Tree is ambiguous, both class com.sun.tools.javac.tree.Tree in com.sun.tools.javac.tree and class com.sun.source.tree.Tree in com.sun.source.tree match [javac] public TypeMirror getTypeMirror(Iterable< ? extends Tree> path) { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java:469: reference to Tree is ambiguous, both class com.sun.tools.javac.tree.Tree in com.sun.tools.javac.tree and class com.sun.source.tree.Tree in com.sun.source.tree match [javac] public Iterable< ? extends Tree> pathFor(CompilationUnitTree unit, Tree node) { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java:469: reference to Tree is ambiguous, both class com.sun.tools.javac.tree.Tree in com.sun.tools.javac.tree and class com.sun.source.tree.Tree in com.sun.source.tree match [javac] public Iterable< ? extends Tree> pathFor(CompilationUnitTree unit, Tree node) { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:434: com.sun.tools.javac.tree.JCTree.JCCompilationUnit is not abstract and does not override abstract method getTypeDecls() in com.sun.source.tree.CompilationUnitTree [javac] public static class JCCompilationUnit extends JCTree implements CompilationUnitTree { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:486: getTypeDecls() in com.sun.tools.javac.tree.JCTree.JCCompilationUnit cannot implement getTypeDecls() in com.sun.source.tree.CompilationUnitTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.util.List<com .sun.tools.javac.tree.JCTree> [javac] required: java.util.List< ? extends com.sun.source.tree.Tree> [javac] public List<jctree> getTypeDecls() { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:503: com.sun.tools.javac.tree.JCTree.JCImport is not abstract and does not override abstract method getQualifiedIdentifier() in com.sun.source.tree.ImportTree [javac] public static class JCImport extends JCTree implements ImportTree { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:515: getQualifiedIdentifier() in com.sun.tools.javac.tree.JCTree.JCImport cannot implement getQualifiedIdentifier() in com.sun.source.tree.ImportTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getQualifiedIdentifier() { return qualid; } [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:566: com.sun.tools.javac.tree.JCTree.JCClassDecl is not abstract and does not override abstract method getMembers() in com.sun.source.tree.ClassTree [javac] public static class JCClassDecl extends JCStatement implements ClassTree { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:604: getMembers() in com.sun.tools.javac.tree.JCTree.JCClassDecl cannot implement getMembers() in com.sun.source.tree.ClassTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.util.List<com .sun.tools.javac.tree.JCTree> [javac] required: java.util.List< ? extends com.sun.source.tree.Tree> [javac] public List<jctree> getMembers() { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:600: getExtendsClause() in com.sun.tools.javac.tree.JCTree.JCClassDecl cannot implement getExtendsClause() in com.sun.source.tree.ClassTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getExtendsClause() { return extending; } [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:624: com.sun.tools.javac.tree.JCTree.JCMethodDecl is not abstract and does not override abstract method getDefaultValue() in com.sun.source.tree.MethodTree [javac] public static class JCMethodDecl extends JCTree implements MethodTree { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:672: getDefaultValue() in com.sun.tools.javac.tree.JCTree.JCMethodDecl cannot implement getDefaultValue() in com.sun.source.tree.MethodTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getDefaultValue() { // for annotation types [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:661: getReturnType() in com.sun.tools.javac.tree.JCTree.JCMethodDecl cannot implement getReturnType() in com.sun.source.tree.MethodTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getReturnType() { return restype; } [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:689: com.sun.tools.javac.tree.JCTree.JCVariableDecl is not abstract and does not override abstract method getType() in com.sun.source.tree.VariableTree [javac] public static class JCVariableDecl extends JCStatement implements VariableTree { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:713: getType() in com.sun.tools.javac.tree.JCTree.JCVariableDecl cannot implement getType() in com.sun.source.tree.VariableTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getType() { return vartype; } [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1456: com.sun.tools.javac.tree.JCTree.JCTypeCast is not abstract and does not override abstract method getType() in com.sun.source.tree.TypeCastTree [javac] public static class JCTypeCast extends JCExpression implements TypeCastTree { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1468: getType() in com.sun.tools.javac.tree.JCTree.JCTypeCast cannot implement getType() in com.sun.source.tree.TypeCastTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getType() { return clazz; } [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1479: com.sun.tools.javac.tree.JCTree.JCInstanceOf is not abstract and does not override abstract method getType() in com.sun.source.tree.InstanceOfTree [javac] public static class JCInstanceOf extends JCExpression implements InstanceOfTree { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1491: getType() in com.sun.tools.javac.tree.JCTree.JCInstanceOf cannot implement getType() in com.sun.source.tree.InstanceOfTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getType() { return clazz; } [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1685: com.sun.tools.javac.tree.JCTree.JCArrayTypeTree is not abstract and does not override abstract method getType() in com.sun.source.tree.ArrayTypeTree [javac] public static class JCArrayTypeTree extends JCExpression implements ArrayTypeTree { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1695: getType() in com.sun.tools.javac.tree.JCTree.JCArrayTypeTree cannot implement getType() in com.sun.source.tree.ArrayTypeTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getType() { return elemtype; } [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1705: com.sun.tools.javac.tree.JCTree.JCTypeApply is not abstract and does not override abstract method getType() in com.sun.source.tree.ParameterizedTypeTree [javac] public static class JCTypeApply extends JCExpression implements ParameterizedTypeTree { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1717: getType() in com.sun.tools.javac.tree.JCTree.JCTypeApply cannot implement getType() in com.sun.source.tree.ParameterizedTypeTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getType() { return clazz; } [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1754: com.sun.tools.javac.tree.JCTree.JCWildcard is not abstract and does not override abstract method getBound() in com.sun.source.tree.WildcardTree [javac] public static class JCWildcard extends JCExpression implements WildcardTree { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1777: getBound() in com.sun.tools.javac.tree.JCTree.JCWildcard cannot implement getBound() in com.sun.source.tree.WildcardTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getBound() { return inner; } [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1802: com.sun.tools.javac.tree.JCTree.JCAnnotation is not abstract and does not override abstract method getAnnotationType() in com.sun.source.tree.AnnotationTree [javac] public static class JCAnnotation extends JCExpression implements AnnotationTree { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1814: getAnnotationType() in com.sun.tools.javac.tree.JCTree.JCAnnotation cannot implement getAnnotationType() in com.sun.source.tree.AnnotationTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getAnnotationType() { return annotationType; } [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1848: com.sun.tools.javac.tree.JCTree.JCErroneous is not abstract and does not override abstract method getErrorTrees() in com.sun.source.tree.ErroneousTree [javac] public static class JCErroneous extends JCExpression [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/JCTree.java:1860: getErrorTrees() in com.sun.tools.javac.tree.JCTree.JCErroneous cannot implement getErrorTrees() in com.sun.source.tree.ErroneousTree; attempting to use incompatible return type [javac] found : com.sun.tools.javac.util.List<com .sun.tools.javac.tree.JCTree> [javac] required: java.util.List< ? extends com.sun.source.tree.Tree> [javac] public List<jctree> getErrorTrees() { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java:451: reference to Tree is ambiguous, both class com.sun.tools.javac.tree.Tree in com.sun.tools.javac.tree and class com.sun.source.tree.Tree in com.sun.source.tree match [javac] Tree last = null; [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java:452: reference to Tree is ambiguous, both class com.sun.tools.javac.tree.Tree in com.sun.tools.javac.tree and class com.sun.source.tree.Tree in com.sun.source.tree match [javac] for (Tree node : path) [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/api/JavacTrees.java:80: com.sun.tools.javac.api.JavacTrees is not abstract and does not override abstract method getTree(javax.lang.model.element.Element,javax.lang.model.element.AnnotationMirror,javax.lang.model.element.AnnotationValue) in com.sun.source.util.Trees [javac] public class JavacTrees extends Trees { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/api/JavacTrees.java:164: getTree(javax.lang.model.element.Element,javax.lang.model.element.AnnotationMirror,javax.lang.model.element.AnnotationValue) in com.sun.tools.javac.api.JavacTrees cannot override getTree(javax.lang.model.element.Element,javax.lang.model.element.AnnotationMirror,javax.lang.model.element.AnnotationValue) in com.sun.source.util.Trees; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getTree(Element e, AnnotationMirror a, AnnotationValue v) { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/api/JavacTrees.java:160: getTree(javax.lang.model.element.Element,javax.lang.model.element.AnnotationMirror) in com.sun.tools.javac.api.JavacTrees cannot override getTree(javax.lang.model.element.Element,javax.lang.model.element.AnnotationMirror) in com.sun.source.util.Trees; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getTree(Element e, AnnotationMirror a) { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/api/JavacTrees.java:143: getTree(javax.lang.model.element.Element) in com.sun.tools.javac.api.JavacTrees cannot override getTree(javax.lang.model.element.Element) in com.sun.source.util.Trees; attempting to use incompatible return type [javac] found : com.sun.tools.javac.tree.JCTree [javac] required: com.sun.source.tree.Tree [javac] public JCTree getTree(Element element) { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/api/JavacTrees.java:187: cannot find symbol [javac] symbol : method getPath(com.sun.tools.javac.tree.JCTree.JCCompilationUnit,com.sun.tools.javac.tree.JCTree) [javac] location: class com.sun.source.util.TreePath [javac] return TreePath.getPath(treeTopLevel.snd, treeTopLevel.fst); [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java:45: com.sun.tools.javac.tree.TreeCopier is not abstract and does not override abstract method visitOther(com.sun.source.tree.Tree,P) in com.sun.source.tree.TreeVisitor [javac] public class TreeCopier<p> implements TreeVisitor<jctree ,P> { [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java:403: inconvertible types [javac] found : com.sun.tools.javac.tree.Tree [javac] required: com.sun.tools.javac.tree.JCTree [javac] JCTree tree = (JCTree) node; [javac] ^ [javac] /Users/elharo/Projects/compiler/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java:406: inconvertible types [javac] found : com.sun.tools.javac.tree.Tree [javac] required: com.sun.tools.javac.tree.JCTree.LetExpr [javac] LetExpr t = (LetExpr) node; [javac] ^ [javac] 41 errors </jctree></p></jctree></com></jctree></com></jctree></com><
I loaded the code into Eclipse, which also complains about some classes. One thing I noticed: they haven’t been using static code analyzers as much as I would. There are lots of unused imports here. Maybe NetBeans isn’t as aggressive as Eclipse about removing such detritus?
November 17th, 2006 at 1:26 AM
I don’t know about aggressive, but it’s certainly not as automated. As I recall, Eclipse highlights things like unused imports, whereas Netbeans is a manual process (Alt+Shift+F/Fix Imports). So if you don’t remember to do it, and aren’t running checkstyle, things like that will get missed.
November 17th, 2006 at 12:20 PM
Were you able to compile it under 1.5? I was able to do a compile from the netbeans project for javac but needed 1.6.
November 17th, 2006 at 4:46 PM
The new version of NB (6.0 nightly) is a lot more agressive with regard
to unused imports – it now grays them down.
November 19th, 2006 at 1:24 PM
I’m pretty sure the *Tree classes they reference are part of the Java Compiler Tree API, in Java 6, which are currently Sun-only classes. There’s a compiler API, which is public, but they’ve exposed an API for the AST so that people can write tools against the AST if they like.
Patrick