File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -794,8 +794,23 @@ String getDescriptor() {
794794 return fieldDescription .getDescriptor ();
795795 }
796796
797- boolean isVisibleTo (TypeDescription typeDescription ) {
798- return fieldDescription .isVisibleTo ( typeDescription );
797+ boolean isVisibleTo (TypeDescription type ) {
798+ final var declaringType = fieldDescription .getDeclaringType ().asErasure ();
799+ if ( declaringType .isVisibleTo ( type ) ) {
800+ if ( fieldDescription .isPublic () || type .equals ( declaringType ) ) {
801+ return true ;
802+ }
803+ else if ( fieldDescription .isProtected () ) {
804+ return declaringType .isAssignableFrom ( type );
805+ }
806+ else if ( fieldDescription .isPrivate () ) {
807+ return type .isNestMateOf ( declaringType );
808+ }
809+ // We explicitly consider package-private fields as not visible, as the classes
810+ // might have the same package name but be loaded by different class loaders.
811+ // (see https://hibernate.atlassian.net/browse/HHH-19784)
812+ }
813+ return false ;
799814 }
800815
801816 FieldDescription getFieldDescription () {
You can’t perform that action at this time.
0 commit comments