attributing files with syntax errors

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


Interesting issue.  Filed as

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 

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 

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 

-- 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
> import no.such.pkg.MissingSymbol;
> class Test {{
>   new MissingSymbol();
> }}
> $ javac -XDshouldStopPolicyIfError=INIT -XDcompilePolicy=todo
> error: package no.such.pkg does not exist
> error: cannot find symbol
> $ javac -XDshouldStopPolicyIfError=ATTR -XDcompilePolicy=todo
> error: package no.such.pkg does not exist
> error: cannot find symbol
> $ javac -XDshouldStopPolicyIfError=INIT -XDcompilePolicy=byfile
> error: package no.such.pkg does not exist
> $ javac -XDshouldStopPolicyIfError=ATTR -XDcompilePolicy=byfile
> error: package no.such.pkg does not exist
> 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] 

More information about the compiler-dev mailing list