United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6595666 fix -Werror
JDK-6595666 : fix -Werror

Details
Type:
Enhancement
Submit Date:
2007-08-22
Status:
Closed
Updated Date:
2012-01-13
Project Name:
JDK
Resolved Date:
2012-01-13
Component:
tools
OS:
generic
Sub-Component:
javac
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Relates:

Sub Tasks

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.
                                     
2009-01-16



Hardware and Software, Engineered to Work Together