Atom Feed SITE FEED   ADD TO GOOGLE READER

Javac bug: the order of imports is significant

The following Java code does something slightly weird - it statically imports a symbol that is defined in the same file. Although it's a little unconventional, it should be perfectly legal:

package com.publicobject.dinosaurs;

import static com.publicobject.dinosaurs.Dinosaur.GeologicPeriod.CRETACEOUS;
import static com.publicobject.dinosaurs.Dinosaur.GeologicPeriod.TRIASSIC;
import static com.publicobject.dinosaurs.Dinosaur.GeologicPeriod.JURASSIC;
import com.publicobject.time.Period;

public class Dinosaur {

private Period period;
private String name;

public static class GeologicPeriod extends Period {
public static final GeologicPeriod TRIASSIC = new GeologicPeriod(-251, -199.6, "Triassic");
public static final GeologicPeriod JURASSIC = new GeologicPeriod(-199.6, -145.5, "Jurassic");
public static final GeologicPeriod CRETACEOUS = new GeologicPeriod(-145.5, -65.5, "Cretaceous");

private String name;

public GeologicPeriod(double startAsMillionYears, double endAsMillionYears, String name) {
super(startAsMillionYears, endAsMillionYears);
this.name = name;
}
}

public Dinosaur(Period period, String name) {
this.period = period;
this.name = name;
}

public boolean isJurassic() {
return period.overlaps(JURASSIC);
}

public boolean isTriassic() {
return period.overlaps(TRIASSIC);
}

public boolean isCretaceous() {
return period.overlaps(CRETACEOUS);
}
}


...except that this Java code does not compile! It fails with a bizarre error, Javac is not able to find the Period class:
/Users/jessewilson/Dinosaurs/IntellijProject/source/com/publicobject/dinosaurs/Dinosaur.java:13: cannot find symbol
symbol : class Period
location: class com.publicobject.Dinosaur
public static class GeologicPeriod extends Period {
^


If I rearrange the imports, moving the import of the Period class ot the top, the code compiles.
Someone has already submitted a bug parade issue on this defect.