JDK-6595666 : fix -Werror
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-08-22
  • Updated: 2017-05-16
  • Resolved: 2012-01-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 Other
7 b48Fixed OpenJDK6Fixed
Related Reports
Relates :  
Description
Currently, javac has an undocumented switch, -Werror, which changes the exit code of the compiler if any warnings were introduced.

It is used by regression tests to verify that warnings were generated. 

A problem with the current impl is that executable output is still generated, which means that a subsequent compilation may not generate the warnings. This is particularly true of build systems that optimistically don't recompile .java files if the .class file is newer (e.g. JDK build, Ant, etc)

The switch is similar to (but weaker than) a similar option in Gnu compilers, in which warnings are treated as real errors.

It would be nice to retain the current behavior under a hidden option for the benefit of the regression tests that use it, and change the impl of -Werror to be more in line with what might be expected. Failoing that, a new documented option should be provided to treat warnings as errors.

Comments
EVALUATION We considered three options: 1) Convert the diagnostic kind of warnings into errors Pro: simple Con: changes the output; might affect tools which use the API to process diagnostics Con: stops processing when it could go further 2) Pretend there has been an error if there have been warnings Pro: leaves diagnostics unchanged Con: stops processing when it could go further 3) Suppress generating class files Pro: See maximum number of diagnostics Con: Still lets annotation processing generate files The final resolution was a variant of (2). We've added code into JavaCompiler.errorCount() to report a new error if -Werror is set and if the error count is zero and the warning count is not. The net effect is that this will cause the compiler to react as it does when an error occurs, without modifying any existing diagnostics. It interacts well with annotation processing, causing an orderly shutdown of annotation processing rounds. I'm (mildly) disappointing we can't let the compilation run for longer, but in the end, we decided it was more important to stop the compiler generating files than it was to continue checking for more diagnostics.
16-01-2009