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.