Inconsistency between ClassDesc::packageName and Class::getPackageName

Kasper Nielsen kasperni at gmail.com
Mon Aug 22 17:13:17 UTC 2022


Hi,

I understand that the methods are behaving as specified.
However, I still think that

int.class.getPackageName() = "java.lang"
int.class.describeConstable().get().packageName() = ""

is surprising behavior. And should probably as a minimum be
documented on ClassDesc::packageName.

/Kasper

On Mon, 22 Aug 2022 at 17:46, Joe Darcy <joe.darcy at oracle.com> wrote:
>
> 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


More information about the core-libs-dev mailing list