JDK-6296560 : javac needs to emit better exit codes, especially for warnings, and needs docs
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-07-13
  • Updated: 2010-04-02
  • Resolved: 2005-07-13
Related Reports
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
If you look at the documentation for javac (e.g. http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javac.html), there is absolutely no mention made about the exit codes that javac can emit in the event that it encounters issues.

By trial and error, I have determined that, at least on Windows, the current behavior of javac is as follows:

If code is pristine, exit code = 0.
If code causes javac to emit a warning but is compilable, exit code = 0.
If code cannot be compiled, exit code = 1.

(See
http://forum.java.sun.com/thread.jspa?threadID=639706
for details on how I determined this, especially my reply #3.)

First, I would actually like you to change the behavior slightly to something like:

If code is pristine, exit code = 0.
If code causes javac to emit a warning but is compilable, exit code = 1.
If code cannot be compiled, exit code = 2.

(Or maybe use even more exit codes if there are different severities of warnings, ranging from style stuff caught by Xlint to more severe problems--the point is that I want the exit code to contain richer information then it does at present.)

This richer behavior would give vastly more information to people who are using javac.

Second, I would like you guys to document and commit to whatever behavior you choose for javac so that it can be counted on for use in development.

Someone else seems to be recommending something similar to my suggestion, incidentally:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6178902


JUSTIFICATION :
Use of javac in any kind of automated build environment would greatly benefit from getting back reliable and extra information concerning the status of the compilation.

Currently, javac emits warnings etc just to the console, which is extremely hard to parse in general and determine if the output is an error or merely a warning. Thus, the utility ofjavac is greatly diminshed.
###@###.### 2005-07-13 20:47:03 GMT

Comments
EVALUATION Changing javac as suggested would not be compatible. It is essential that zero means compilation success (even with warnings). For more complete access to the diagnostics reported by javac, use the APIs of jsr 199. See: http://jcp.org/aboutJava/communityprocess/edr/jsr199/ http://jcp.org/en/jsr/detail?id=199 ###@###.### 2005-07-13 21:33:47 GMT
13-07-2005