attributing files with syntax errors

Jonathan Gibbons jonathan.gibbons at oracle.com
Fri Aug 21 01:04:05 UTC 2015


Liam,

Interesting issue.  Filed as 
https://bugs.openjdk.java.net/browse/JDK-8134117.

Twiddling the CompilePolicy is an "internal" knob, controlled by a 
"hidden" (-XD) option. That being said, my primary concern about 
changing the bytodo policy is that it is the default policy, so changing 
it will potentially affect everyone, even those who don't know about the 
CompilePolicy.

And _that_ being said, the original intent of providing the 
CompilePolicy was to address bugs in which a file had multiple top level 
classes, and some could have classes generated before errors were 
detected in other classes in the same file.  Hence the byfile policy. 
But for various reasons, byfile never became the default. I seem to 
recall it was at least in part due to memory usage, which is less of a 
concern today than it was back then.

The other area where this might be relevant is annotation processing, 
where the original code was not so good back then at differentiating 
different types of errors, and so we wanted compilation to continue more 
often than we do now. Nowadays, javac has a better concept of 
"recoverable errors", and so javac is better at not proceeding 
unnecessarily.

So I guess I'd be interested to see the patch, although to prevent 
unnecessary work up front, it may be worth posting the src/ patch first, 
with some info on just how many and which tests need fixing.   The more 
tests that need fixup, the more carefully we should review the change in 
behavior.

-- Jon


On 08/20/2015 05:21 PM, Liam Miller-Cushon wrote:
> I spent some time yesterday being surprised by the behaviour of 
> -XDcompilePolicy=todo:
>
> $ cat Test.java
> import no.such.pkg.MissingSymbol;
>
> class Test {{
>   new MissingSymbol();
> }}
>
> $ javac -XDshouldStopPolicyIfError=INIT -XDcompilePolicy=todo Test.java
> Test.java:1: error: package no.such.pkg does not exist
> Test.java:4: error: cannot find symbol
>
> $ javac -XDshouldStopPolicyIfError=ATTR -XDcompilePolicy=todo Test.java
> Test.java:1: error: package no.such.pkg does not exist
> Test.java:4: error: cannot find symbol
>
> $ javac -XDshouldStopPolicyIfError=INIT -XDcompilePolicy=byfile Test.java
> Test.java:1: error: package no.such.pkg does not exist
>
> $ javac -XDshouldStopPolicyIfError=ATTR -XDcompilePolicy=byfile Test.java
> Test.java:1: error: package no.such.pkg does not exist
> Test.java:4: error: cannot find symbol
>
> In the first compilation, the 'cannot find symbol' error is emitted 
> despite -XDshouldStopPolicyIfError=INIT. I expected the output to look 
> like it does with a byfile policy (the third example).
>
> This appears to be a known issue: "in bytodo mode, javac will still 
> attribute files after syntax errors. Changing that behavior may 
> surprise existing users, so for now, we work around it." [1] This 
> seems to affect all policies except byfile.
>
> Is there any chance this can be fixed? It's a simple patch, which I'd 
> be happy to contribute. Most of the work is fixing up existing tests 
> that produce different diagnostics after the fix.
>
> If the fix is still too risky, is it worth considering changing byfile 
> to match the other policies? I think the difference between policies 
> is more surprising than fixing the bug would be. If that isn't an 
> option either, it'd be nice to at least create a tracking bug and 
> document the issue somewhere more discoverable.
>
> Thanks,
> Liam
>
> [1] 
> http://hg.openjdk.java.net/jdk9/dev/langtools/file/eaab8a16dcfb/test/tools/javac/policy/test3/Test.java#l98



More information about the compiler-dev mailing list