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

ClassLoader.getPackages() tracks only entries found in jars.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.2
    • core-libs
    • x86
    • windows_95

      Name: mc57594 Date: 11/27/99

      Looks like possible duplicate of
      4259825 kestrel M fails: java_lang/versioning/PackageVersioning.html#PkgVersioning0001
      but that was claimed to have worked in jdk1.2.2.

      [chamness]
      =-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-
      java version "1.2.2"
      Classic VM (build JDK-1.2.2-U, native threads, symcjit)


      In a java application of your choice, where the current class IS NOT loaded from
      a jar, do this:

      Package[] pa=Package.getPackages();
      for (int i=0;i<pa.length;i++) System.err.println("pa["+i+"]="+pa[i].getName());

      You will find that the package for the current class is not listed.

      You will also find that only classes loaded from jars will be listed.

      While it is required that the class loader doing the loading of classes must
      know what the URL is for any package specified by any loaded class, it is
      unclear under why the implementation goes to the trouble of making this
      distinction.

      Assuming you have read this far, and to avoid another "show me where in the
      documentation it says this is an error" question, I paste here what the manual
      says:

      from: file:///C|/jdk1.2/docs/api/java/lang/Package.html#getPackages()

      getPackages

      public static Package[] getPackages()

           Get all the packages currently known for the caller's class loader. Those
      packages correspond to classes loaded via or accessible by name to that class
           loader. If the caller's class loader is the bootstrap classloader, which
      may be represented by null in some implementations, only packages
           corresponding to classes loaded by the bootstrap class loader will be
      returned.
           Returns:
                a new array of packages known to the callers classloader. An zero
      length array is returned if none are known.



      As you can see, the phrase "Get all the packages currently known for the
      caller's class loader" is quite clear.

      I think it should include the package that the current class is in.

      This is not the case, when the current class was not loaded from a jar.
      (Review ID: 98272)
      ======================================================================
      From: Ken
      To: "'chamness'"
      Subject: RE: (Review ID: 98272) ClassLoader.getPackages() tracks only entr ies found in jars.
      Date: Mon, 29 Nov 1999 09:36:24 -0800

      Please find attached a file "bug.jar".

      Here is the output:
      C:\My Documents\java\jorg>java -jar bug.jar
      pa=[Ljava.lang.Package;@35a36186
      pa[0]=sun.io
      pa[1]=java.net
      pa[2]=sun.security.action
      pa[3]=java.util.zip
      pa[4]=sun.net.www
      pa[5]=java.security
      pa[6]=sun.security.provider
      pa[7]=sun.security.util
      pa[8]=sun.misc
      pa[9]=java.lang
      pa[10]=java.lang.reflect
      pa[11]=java.util
      pa[12]=sun.net.www.protocol.jar
      pa[13]=java.lang.ref
      pa[14]=sun.net.www.protocol.file
      pa[15]=java.io
      pa[16]=java.util.jar
      pa[17]=pjda.pjutil
      *** Package included in Class Loaders list ***

      C:\My Documents\java\jorg>java -classpath "." pjda.pjutil.bug
      pa=[Ljava.lang.Package;@489761fc
      pa[0]=sun.io
      pa[1]=java.net
      pa[2]=sun.security.action
      pa[3]=java.util.zip
      pa[4]=sun.net.www
      pa[5]=java.security
      pa[6]=sun.security.provider
      pa[7]=sun.security.util
      pa[8]=sun.misc
      pa[9]=java.lang
      pa[10]=java.lang.reflect
      pa[11]=java.util
      pa[12]=sun.net.www.protocol.jar
      pa[13]=java.lang.ref
      pa[14]=sun.net.www.protocol.file
      pa[15]=java.io
      pa[16]=java.util.jar


      Please let me know if there is any more assistance you need.

      Thanks in advance,

      Ken

            zlisunw Zhenghua Li (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: