Skip to content

Commit 0e49cc3

Browse files
committed
Adjust visibility and accessability checks.
1 parent 3c868d0 commit 0e49cc3

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

byte-buddy-dep/src/main/java/net/bytebuddy/description/method/MethodDescription.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -610,23 +610,21 @@ public int getActualModifiers(boolean manifest, Visibility visibility) {
610610
* {@inheritDoc}
611611
*/
612612
public boolean isVisibleTo(TypeDescription typeDescription) {
613-
return (isVirtual() || getDeclaringType().asErasure().isVisibleTo(typeDescription))
614-
&& (isPublic()
615-
|| typeDescription.equals(getDeclaringType().asErasure())
616-
|| isProtected() && getDeclaringType().asErasure().isAssignableFrom(typeDescription)
617-
|| !isPrivate() && typeDescription.isSamePackage(getDeclaringType().asErasure())
618-
|| isPrivate() && typeDescription.isNestMateOf(getDeclaringType().asErasure()));
613+
return getDeclaringType().asErasure().equals(typeDescription)
614+
|| isPublic() && getDeclaringType().isPublic()
615+
|| (isPublic() || isProtected()) && getDeclaringType().asErasure().isAssignableFrom(typeDescription)
616+
|| !isPrivate() && getDeclaringType().asErasure().isSamePackage(typeDescription)
617+
|| isPrivate() && getDeclaringType().asErasure().isNestMateOf(typeDescription);
619618
}
620619

621620
/**
622621
* {@inheritDoc}
623622
*/
624623
public boolean isAccessibleTo(TypeDescription typeDescription) {
625-
return (isVirtual() || getDeclaringType().asErasure().isVisibleTo(typeDescription))
626-
&& (isPublic()
627-
|| typeDescription.equals(getDeclaringType().asErasure())
628-
|| !isPrivate() && typeDescription.isSamePackage(getDeclaringType().asErasure()))
629-
|| isPrivate() && typeDescription.isNestMateOf(getDeclaringType().asErasure());
624+
return getDeclaringType().asErasure().equals(typeDescription)
625+
|| isPublic() && getDeclaringType().isPublic()
626+
|| !isPrivate() && getDeclaringType().asErasure().isSamePackage(typeDescription)
627+
|| isPrivate() && getDeclaringType().asErasure().isNestMateOf(typeDescription);
630628
}
631629

632630
/**

byte-buddy-dep/src/test/java/net/bytebuddy/description/method/AbstractMethodDescriptionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public void testMethodIsVisibleTo() throws Exception {
430430
assertThat(describe(PublicType.class.getDeclaredMethod("privateMethod"))
431431
.isVisibleTo(TypeDescription.ForLoadedType.of(MethodDescriptionTestHelper.class)), is(false));
432432
assertThat(describe(PackagePrivateType.class.getDeclaredMethod("publicMethod"))
433-
.isVisibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(true));
433+
.isVisibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(false));
434434
assertThat(describe(PackagePrivateType.class.getDeclaredMethod("protectedMethod"))
435435
.isVisibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(false));
436436
assertThat(describe(PackagePrivateType.class.getDeclaredMethod("packagePrivateMethod"))
@@ -535,7 +535,7 @@ public void testMethodIsAccessibleTo() throws Exception {
535535
assertThat(describe(PublicType.class.getDeclaredMethod("privateMethod"))
536536
.isAccessibleTo(TypeDescription.ForLoadedType.of(MethodDescriptionTestHelper.class)), is(false));
537537
assertThat(describe(PackagePrivateType.class.getDeclaredMethod("publicMethod"))
538-
.isAccessibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(true));
538+
.isAccessibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(false));
539539
assertThat(describe(PackagePrivateType.class.getDeclaredMethod("protectedMethod"))
540540
.isAccessibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(false));
541541
assertThat(describe(PackagePrivateType.class.getDeclaredMethod("packagePrivateMethod"))

0 commit comments

Comments
 (0)