Skip to content

Commit d5a6b59

Browse files
committed
HHH-19784 Fix for package-private fields in same hierarchy using different class loaders
1 parent 7e9b192 commit d5a6b59

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
@@ -823,8 +823,23 @@ String getDescriptor() {
823823
return fieldDescription.getDescriptor();
824824
}
825825

826-
boolean isVisibleTo(TypeDescription typeDescription) {
827-
return fieldDescription.isVisibleTo( typeDescription );
826+
boolean isVisibleTo(TypeDescription type) {
827+
final var declaringType = fieldDescription.getDeclaringType().asErasure();
828+
if ( declaringType.isVisibleTo( type ) ) {
829+
if ( fieldDescription.isPublic() || type.equals( declaringType ) ) {
830+
return true;
831+
}
832+
else if ( fieldDescription.isProtected() ) {
833+
return declaringType.isAssignableFrom( type );
834+
}
835+
else if ( fieldDescription.isPrivate() ) {
836+
return type.isNestMateOf( declaringType );
837+
}
838+
// We explicitly consider package-private fields as not visible, as the classes
839+
// might have the same package name but be loaded by different class loaders.
840+
// (see https://hibernate.atlassian.net/browse/HHH-19784)
841+
}
842+
return false;
828843
}
829844

830845
FieldDescription getFieldDescription() {

0 commit comments

Comments
 (0)