From 9a3e7e2d552433c4826e0c0d25c63d9688468120 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Tue, 27 Jul 2021 20:24:52 +0200 Subject: [PATCH] Restrict constraint for field setting since field is always set on own instance. --- .../main/java/net/bytebuddy/implementation/MethodCall.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/implementation/MethodCall.java b/byte-buddy-dep/src/main/java/net/bytebuddy/implementation/MethodCall.java index a79a216d22d..ef27d9f7231 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/implementation/MethodCall.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/implementation/MethodCall.java @@ -3138,7 +3138,7 @@ protected Explicit(FieldDescription fieldDescription) { public TerminationHandler make(TypeDescription instrumentedType) { if (!fieldDescription.isStatic() && !instrumentedType.isAssignableTo(fieldDescription.getDeclaringType().asErasure())) { throw new IllegalStateException("Cannot set " + fieldDescription + " from " + instrumentedType); - } else if (!fieldDescription.isAccessibleTo(instrumentedType)) { + } else if (!fieldDescription.isVisibleTo(instrumentedType)) { throw new IllegalStateException("Cannot access " + fieldDescription + " from " + instrumentedType); } return new FieldSetting(fieldDescription); @@ -3171,7 +3171,7 @@ protected Implicit(ElementMatcher matcher) { public TerminationHandler make(TypeDescription instrumentedType) { TypeDefinition current = instrumentedType; do { - FieldList candidates = current.getDeclaredFields().filter(isAccessibleTo(instrumentedType).and(matcher)); + FieldList candidates = current.getDeclaredFields().filter(isVisibleTo(instrumentedType).and(matcher)); if (candidates.size() == 1) { return new FieldSetting(candidates.getOnly()); } else if (candidates.size() == 2) {