Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6960424

new option -Xpkginfo for better control of when package-info.class is generated

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 7
    • tools
    • b112
    • generic
    • generic
    • Verified

      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.

            jjg Jonathan Gibbons
            jjg Jonathan Gibbons
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: