Skip to content

Inconsistency in default package handling #474

@gsmet

Description

@gsmet

Hi,

While working on fixing a few things in the ByteBuddy enhancer for Hibernate ORM, we noticed an issue with classes in the default package: we know it's a corner case but we are supporting it.

The issue lies in the inconsistency between:

  • The InstrumentedType.Default getPackage() method:
        @Override
        public PackageDescription getPackage() {
            int packageIndex = name.lastIndexOf('.');
            return packageIndex == -1
                    ? PackageDescription.UNDEFINED
                    : new PackageDescription.Simple(name.substring(0, packageIndex));
        }

which returns PackageDescription.UNDEFINED thus null for an empty package name

  • And the TypeDescription.ForLoadedType getPackage() method:
        @Override
        public PackageDescription getPackage() {
            Package aPackage = type.getPackage();
            return (aPackage == null)
                    ? PackageDescription.UNDEFINED
                    : new PackageDescription.ForLoadedPackage(aPackage);
        }

which returns a package with an empty name in the case of the default package.

I don't know if you meant UNDEFINED as being the default package but in any case both methods should be consistent.

Our issue is that at some point TypeDescription.isSamePackage(TypeDescription) fails because one is of the former type and the other from the latter and comparing the packages returns false.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions