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

(cl spec) clarify spec of ClassLoader.getPackages() about run-time package

XMLWordPrintable

      A DESCRIPTION OF THE REQUEST :
      Javadoc currently reads: "Returns all of the Packages defined by this class loader and its ancestors". Yet this is not really true. Packages that represent folders inside another package defined in this class loader will not appear in the returned list until at least one class has been loaded from the package. For example, if the classpath contains an entry "com.abc.mainpkg", the class loader may be able to load "com.abc.mainpkg.subpkg.Foo", but until it actually does (or loads something from "subpkg"), the return value for getPackages() may not include "com.abc.mainpkg.subpkg". Thus, the javadoc is misleading.

      JUSTIFICATION :
      Because developers design their code wrong and then have to rewrite it when the method doesn't work as advertised.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Change the doc. Perhaps add an explanation at the end along the lines of this. "Note: packages that represent folders inside another package may not appear in the returned list of packages until at least one class has been loaded from the folder."

            mchung Mandy Chung
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: