Inconsistency between ClassDesc::packageName and Class::getPackageName
Alan Bateman
Alan.Bateman at oracle.com
Mon Aug 22 18:57:05 UTC 2022
On 22/08/2022 18:13, Kasper Nielsen wrote:
> 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.
>
A named module is a set of named packages and it just wouldn't work for
a class in a named module to say that it's in the unnamed package. As I
recall, the original proposal for getPackageName was that it return null
when the class is for an array or primitive class but that turned out to
be a usability issue. The proposal was refined to what is specified now.
ClassDesc is a nominal descriptor so it's more like parsing a string to
get the package name. I don't disagree that the packageName method could
link to isArray and componentType when the descriptor is for an array
type, or isPrimitive to test if the descriptor is for a primitive type.
-Alan.
More information about the core-libs-dev
mailing list