Inconsistency between ClassDesc::packageName and Class::getPackageName

Joe Darcy joe.darcy at oracle.com
Mon Aug 22 16:46:29 UTC 2022


Hello,

The method Class.getPackage is behaving as specified:

> public Package getPackage()
> Gets the package of this class.
>
> If this class represents an array type, a primitive type or void, this 
> method returns null.

as is Class.getPackageName():

> If this class represents an array type then this method returns the 
> package name of the element type. If this class represents a primitive 
> type or void then the package name "|java.lang|" is returned.

and ClassDesc.packageName is as well.

Class.getPackage has been doing what it been doing since about JDK 1.2 
so due to behavioral compatibility, there would have to be a much 
stronger case for altering its behavior at this point.

-Joe

On 8/22/2022 2:17 AM, Kasper Nielsen wrote:
> Hi,
>
> I was playing around with java.lang.constant and found an inconsistency between
> ClassDesc::packageName and Class::getPackageName as outlined in the table below.
> Specifically dealing with primitive and array types.
>
> Class       ClassDesc::packageName Class::getPackage Class::getPackageName
>   ---------- ---------------------- ----------------- ---------------------
>    int        ""                     null              "java.lang"
>    int[]      ""                     null              "java.lang"
>    Integer    "java.lang"            java.lang         "java.lang"
>    Integer[]  ""                     null              "java.lang"
>
> I was originally going to submit a patch for ClassDesc. But I now think
> Class::getPackageName is the one that I need to patch. Thoughts?
>
> Thanks,
>    Kasper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20220822/6c642f84/attachment-0001.htm>


More information about the core-libs-dev mailing list