From 0e49cc3debf1b1db45a14d234c93d545089bccf3 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Thu, 15 Aug 2024 22:14:53 +0200 Subject: [PATCH] Adjust visibility and accessability checks. --- .../description/method/MethodDescription.java | 20 +++++++++---------- .../method/AbstractMethodDescriptionTest.java | 4 ++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/description/method/MethodDescription.java b/byte-buddy-dep/src/main/java/net/bytebuddy/description/method/MethodDescription.java index 727eb45b95..737a3ef7b4 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/description/method/MethodDescription.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/description/method/MethodDescription.java @@ -610,23 +610,21 @@ public int getActualModifiers(boolean manifest, Visibility visibility) { * {@inheritDoc} */ public boolean isVisibleTo(TypeDescription typeDescription) { - return (isVirtual() || getDeclaringType().asErasure().isVisibleTo(typeDescription)) - && (isPublic() - || typeDescription.equals(getDeclaringType().asErasure()) - || isProtected() && getDeclaringType().asErasure().isAssignableFrom(typeDescription) - || !isPrivate() && typeDescription.isSamePackage(getDeclaringType().asErasure()) - || isPrivate() && typeDescription.isNestMateOf(getDeclaringType().asErasure())); + return getDeclaringType().asErasure().equals(typeDescription) + || isPublic() && getDeclaringType().isPublic() + || (isPublic() || isProtected()) && getDeclaringType().asErasure().isAssignableFrom(typeDescription) + || !isPrivate() && getDeclaringType().asErasure().isSamePackage(typeDescription) + || isPrivate() && getDeclaringType().asErasure().isNestMateOf(typeDescription); } /** * {@inheritDoc} */ public boolean isAccessibleTo(TypeDescription typeDescription) { - return (isVirtual() || getDeclaringType().asErasure().isVisibleTo(typeDescription)) - && (isPublic() - || typeDescription.equals(getDeclaringType().asErasure()) - || !isPrivate() && typeDescription.isSamePackage(getDeclaringType().asErasure())) - || isPrivate() && typeDescription.isNestMateOf(getDeclaringType().asErasure()); + return getDeclaringType().asErasure().equals(typeDescription) + || isPublic() && getDeclaringType().isPublic() + || !isPrivate() && getDeclaringType().asErasure().isSamePackage(typeDescription) + || isPrivate() && getDeclaringType().asErasure().isNestMateOf(typeDescription); } /** diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/description/method/AbstractMethodDescriptionTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/description/method/AbstractMethodDescriptionTest.java index c26a8f41cd..5ec91b6cf7 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/description/method/AbstractMethodDescriptionTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/description/method/AbstractMethodDescriptionTest.java @@ -430,7 +430,7 @@ public void testMethodIsVisibleTo() throws Exception { assertThat(describe(PublicType.class.getDeclaredMethod("privateMethod")) .isVisibleTo(TypeDescription.ForLoadedType.of(MethodDescriptionTestHelper.class)), is(false)); assertThat(describe(PackagePrivateType.class.getDeclaredMethod("publicMethod")) - .isVisibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(true)); + .isVisibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(false)); assertThat(describe(PackagePrivateType.class.getDeclaredMethod("protectedMethod")) .isVisibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(false)); assertThat(describe(PackagePrivateType.class.getDeclaredMethod("packagePrivateMethod")) @@ -535,7 +535,7 @@ public void testMethodIsAccessibleTo() throws Exception { assertThat(describe(PublicType.class.getDeclaredMethod("privateMethod")) .isAccessibleTo(TypeDescription.ForLoadedType.of(MethodDescriptionTestHelper.class)), is(false)); assertThat(describe(PackagePrivateType.class.getDeclaredMethod("publicMethod")) - .isAccessibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(true)); + .isAccessibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(false)); assertThat(describe(PackagePrivateType.class.getDeclaredMethod("protectedMethod")) .isAccessibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(false)); assertThat(describe(PackagePrivateType.class.getDeclaredMethod("packagePrivateMethod"))