JDK-6960424 : new option -Xpkginfo for better control of when package-info.class is generated
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2010-06-11
  • Updated: 2017-05-16
  • Resolved: 2011-03-07
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
7 b112Fixed
Related Reports
Relates :  
Description
package-info.java can contain javadoc comments about a package, or annotations for a package or both.   If it contains annotations, then a package-info.class file will be generated. By implication, if it does /not/ contain annotations, a package-info.class file will not be generated.   

There are two issues with the current behavior.

1. The current behavior is mildly simplistic and inconsistent, in that package-info.class files are still generated even if all the annotations involved have a retention policy of "source".  This seems contrary to the intent of only generating package-info files when they will be non-empty.

2. The current behavior is very inconvenient for build systems, like Ant, which try and optimize the number of Java source files to be compiled by comparing timestamps of corresponding .java and .class files.  In such a world, a .java file that does not have a corresponding .class file will always be compiled, leading to unstable builds. This has led to problems in Ant 1.7.1 and later, trying to workaround the javac behavior, with the latest workaround being to generate empty package-info.class files even if javac does not.

The proposed fix is to add a new non-standard option -Xpkginfo:value to control javac's behavior for generating package-info.class files.  The option will take one of the following values:
	always   (always generate package-info.class files)
	nonempty (generate package-info.class files if they are non-empty)
	legacy	 (current behavior)

The value of "always" can be used to fix issue 2 above; the value of "nonempty" provides a new behavior fixing issue 1 above; and the value of "legacy" provides the current behavior for those that require it.

Comments
EVALUATION A fine idea.
19-08-2010