RFR: 8198378: javac crash when checking imports and a broken class is present

Vicente Romero vicente.romero at oracle.com
Fri Jun 1 21:14:54 UTC 2018


looks good,

Vicente


On 06/01/2018 11:19 AM, Jan Lahoda wrote:
> Hi,
>
> Consider these two files:
> ---pkg/Missing.java
> broken
> ---Test.java
> import pkg.Missing;
> ---
>
> Compiled like this:
> $ javac -sourcepath . -XDdev Test.java
>
> This crashes in Check.isCanonical, because in Resolve.loadClass, the 
> BadClassFile exception is rethrown, which in turn will lead to 
> unattributed "pkg.Missing" tree, which will lead to the 
> Check.isCanonical crash. The BadClassFile should be handled on this 
> place (I tried it to do in a way that does not change the printed error).
>
> While looking at this, it turned out that in a case like this:
> ---pkg/Missing.java
> broken
> ---Test.java
> import pkg.*;
> public class Test {
>     Missing m;
> }
> ---
>
> When this is compiled, it will lead to an error that does not seem ideal:
> ---
> Test.java:3: error: cannot find symbol
>     Missing m;
>     ^
>   symbol:   class Missing
>   location: class Test
> ---
>
> The reason is that the BadClassFile is caught and thrown away in 
> Check.importAccessible. Rethrowing he error, and handling it more 
> appropriately in TypeEnter leads to:
> ---
> Test.java:3: error: cannot access Missing
>     Missing m;
>     ^
>   bad source file: ./pkg/Missing.java
>     file does not contain class pkg.Missing
>     Please remove or make sure it appears in the correct subdirectory 
> of the sourcepath.
> ---
>
> For this, I tried to make the behavior close to the JDK 8 behavior for 
> cases like:
> import pkg.Class.*; //which (by itself) passed even if there was a 
> broken subclass
> import static pkg.Class.*; //which caused a compile-time error
>
> (This is the purpose of the change in Scope.)
>
> Bug: https://bugs.openjdk.java.net/browse/JDK-8198378
> Webrev: http://cr.openjdk.java.net/~jlahoda/8198378/webrev.00/
>
> How does this look?
>
> Thanks,
>     Jan



More information about the compiler-dev mailing list