Compilation (still) depends on order of imports

Liam Miller-Cushon cushon at google.com
Mon Mar 16 15:23:28 UTC 2015


Hi Jan,

I see the same behaviour with JDK 9 b54. I've included a more verbose
version of the repro below. Sorry if I'm missing something obvious.

One additional bit of weirdness is that the order of the source files
passed to javac matters: the issue occurs for "P/Outer.java P/Q/C.java
P/Q/D.java" but not "P/Q/C.java P/Q/D.java P/Outer.java".

Here's the repro:

$ ~/jdk/jdk1.9.0/bin/java -version
java version "1.9.0-ea"
Java(TM) SE Runtime Environment (build 1.9.0-ea-b54)
Java HotSpot(TM) 64-Bit Server VM (build 1.9.0-ea-b54, mixed mode)

$ for f in $(find . -name "*.java"); do echo "=== $f ==="; cat $f; done
=== ./P/Q/C.java ===
package P.Q;

public class C extends D {
}
=== ./P/Q/D.java ===
package P.Q;

public class D {
  public interface I {
  }
}
=== ./P/Outer.java ===
package P;

import static P.Outer.Nested.*;
import static P.Q.C.*;

public class Outer {
  public static class Nested implements I {
  }
}

$ ~/jdk/jdk1.9.0/bin/javac P/Outer.java P/Q/C.java P/Q/D.java
P/Outer.java:7: error: cannot find symbol
  public static class Nested implements I {
                                        ^
  symbol:   class I
  location: class Outer
1 error

# Now, flip the order of the two imports in P.Outer

$ for f in $(find . -name "*.java"); do echo "=== $f ==="; cat $f; done
=== ./P/Q/C.java ===
package P.Q;

public class C extends D {
}
=== ./P/Q/D.java ===
package P.Q;

public class D {
  public interface I {
  }
}
=== ./P/Outer.java ===
package P;

import static P.Q.C.*;
import static P.Outer.Nested.*;

public class Outer {
  public static class Nested implements I {
  }
}

$ ~/jdk/jdk1.9.0/bin/javac P/Outer.java P/Q/C.java P/Q/D.java

# ... compiles cleanly



On Mon, Mar 16, 2015 at 1:08 AM, Jan Lahoda <jan.lahoda at oracle.com> wrote:

> Hi Liam,
>
> Thanks for the report. I am afraid I was not able to reproduce. I tried on:
> $ javac -fullversion
> javac full version "1.9.0-ea-b54"
>
> and on a custom build from jdk9/dev/langtools, tip:
> $ hg tip
> changeset:   2850:32a2e7249884
> tag:         tip
> parent:      2849:75cedc6db8c2
> parent:      2848:f5a1cb1309ae
> user:        lana
> date:        Thu Mar 12 21:13:42 2015 -0700
> summary:     Merge
>
> Is there something special I need to do? Could you please try on JDK 9 b54?
>
> Thanks,
>     Jan
>
>
> On 15.3.2015 23:00, Liam Miller-Cushon wrote:
>
>> I think I found a bug related to JEP 216. With javac9-dev @ r2850, the
>> following program fails to compile unless the order of imports is
>> reversed.
>>
>> It looks like the current implementation isn't lazy enough to handle the
>> dependency between the two on-demand imports if 'I' is inherited into
>> 'C'. If 'I' is declared directly in 'C' then it works.
>>
>> {{{
>> package P;
>>
>> import static P.Outer.Nested.*;
>> import static P.Q.C.*;
>>
>> public class Outer {
>>    public static class Nested implements I {
>>    }
>> }
>>
>> package P.Q;
>>
>> public class C extends D {
>> }
>>
>> package P.Q;
>>
>> public class D {
>>    public interface I {
>>    }
>> }
>> }}}
>>
>> $ javac P/Outer.java P/Q/D.java P/Q/C.java
>> P/Outer.java:7: error: cannot find symbol
>>    public static class Nested implements I {
>>                                          ^
>>    symbol:   class I
>>    location: class Outer
>> 1 error
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150316/9a565b15/attachment.html>


More information about the compiler-dev mailing list