Skip to content

Commit 0b32b3f

Browse files
committed
HHH-19784 Fix for package-private fields in same hierarchy using different class loaders
1 parent 3984cd6 commit 0b32b3f

File tree

1 file changed

+17
-2
lines changed
  • hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy

1 file changed

+17
-2
lines changed

hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/EnhancerImpl.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,23 @@ String getDescriptor() {
810810
return fieldDescription.getDescriptor();
811811
}
812812

813-
boolean isVisibleTo(TypeDescription typeDescription) {
814-
return fieldDescription.isVisibleTo( typeDescription );
813+
boolean isVisibleTo(TypeDescription type) {
814+
final var declaringType = fieldDescription.getDeclaringType().asErasure();
815+
if ( declaringType.isVisibleTo( type ) ) {
816+
if ( fieldDescription.isPublic() || type.equals( declaringType ) ) {
817+
return true;
818+
}
819+
else if ( fieldDescription.isProtected() ) {
820+
return declaringType.isAssignableFrom( type );
821+
}
822+
else if ( fieldDescription.isPrivate() ) {
823+
return type.isNestMateOf( declaringType );
824+
}
825+
// We explicitly consider package-private fields as not visible, as the classes
826+
// might have the same package name but be loaded by different class loaders.
827+
// (see https://hibernate.atlassian.net/browse/HHH-19784)
828+
}
829+
return false;
815830
}
816831

817832
FieldDescription getFieldDescription() {

0 commit comments

Comments
 (0)