From a663cf78f3bff0bf7d646e1f0c5b93b0a14c05c5 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Wed, 6 Jan 2016 13:26:14 +0100 Subject: [PATCH] Fixed reference of method instead of type. --- .../scaffold/inline/MethodRebaseResolver.java | 2 +- .../inline/RebaseImplementationTargetTest.java | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/inline/MethodRebaseResolver.java b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/inline/MethodRebaseResolver.java index 96cc8042992..8e9babbac86 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/inline/MethodRebaseResolver.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/inline/MethodRebaseResolver.java @@ -474,7 +474,7 @@ public static MethodRebaseResolver make(TypeDescription instrumentedType, DynamicType placeholderType = null; Map resolutions = new HashMap(); for (MethodDescription.InDefinedShape instrumentedMethod : instrumentedType.getDeclaredMethods()) { - if (rebaseableMethods.contains(instrumentedMethod.asToken(is(instrumentedMethod)))) { + if (rebaseableMethods.contains(instrumentedMethod.asToken(is(instrumentedType)))) { Resolution resolution; if (instrumentedMethod.isConstructor()) { if (placeholderType == null) { diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/inline/RebaseImplementationTargetTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/inline/RebaseImplementationTargetTest.java index c4085d391f4..6ea558f7d7f 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/inline/RebaseImplementationTargetTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/inline/RebaseImplementationTargetTest.java @@ -10,6 +10,7 @@ import net.bytebuddy.implementation.Implementation; import net.bytebuddy.implementation.bytecode.StackManipulation; import net.bytebuddy.implementation.bytecode.constant.NullConstant; +import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.test.utility.ObjectPropertyAssertion; import org.junit.Before; import org.junit.Test; @@ -33,7 +34,10 @@ public class RebaseImplementationTargetTest extends AbstractImplementationTarget private MethodDescription.InDefinedShape rebasedMethod; @Mock - private MethodDescription.SignatureToken rebasedToken; + private MethodDescription.Token rebasedToken; + + @Mock + private MethodDescription.SignatureToken rebasedSignatureToken; @Mock private MethodRebaseResolver.Resolution resolution; @@ -52,12 +56,13 @@ public void setUp() throws Exception { when(genericSuperType.asErasure()).thenReturn(superType); when(superType.getInternalName()).thenReturn(BAR); when(rebasedMethod.getInternalName()).thenReturn(QUX); + when(rebasedMethod.asToken(ElementMatchers.is(instrumentedType))).thenReturn(rebasedToken); when(rebasedMethod.getDescriptor()).thenReturn(FOO); when(rebasedMethod.asDefined()).thenReturn(rebasedMethod); when(rebasedMethod.getReturnType()).thenReturn(genericReturnType); when(rebasedMethod.getParameters()).thenReturn(new ParameterList.Empty()); when(rebasedMethod.getDeclaringType()).thenReturn(instrumentedType); - when(rebasedMethod.asSignatureToken()).thenReturn(rebasedToken); + when(rebasedMethod.asSignatureToken()).thenReturn(rebasedSignatureToken); when(methodRebaseResolver.resolve(rebasedMethod)).thenReturn(resolution); super.setUp(); } @@ -75,7 +80,7 @@ public void testNonRebasedMethodIsInvokable() throws Exception { when(invokableMethod.isSpecializableFor(instrumentedType)).thenReturn(true); when(resolution.isRebased()).thenReturn(false); when(resolution.getResolvedMethod()).thenReturn(invokableMethod); - Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedToken); + Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedSignatureToken); verify(methodRebaseResolver).asTokenMap(); verifyNoMoreInteractions(methodRebaseResolver); assertThat(specialMethodInvocation.isValid(), is(true)); @@ -98,7 +103,7 @@ public void testRebasedMethodIsInvokable() throws Exception { when(resolution.getResolvedMethod()).thenReturn(rebasedMethod); when(resolution.getAdditionalArguments()).thenReturn(StackManipulation.Trivial.INSTANCE); when(rebasedMethod.isSpecializableFor(instrumentedType)).thenReturn(true); - Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedToken); + Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedSignatureToken); verify(methodRebaseResolver).asTokenMap(); verifyNoMoreInteractions(methodRebaseResolver); assertThat(specialMethodInvocation.isValid(), is(true)); @@ -122,7 +127,7 @@ public void testRebasedConstructorIsInvokable() throws Exception { when(resolution.getResolvedMethod()).thenReturn(rebasedMethod); when(resolution.getAdditionalArguments()).thenReturn(NullConstant.INSTANCE); when(rebasedMethod.isSpecializableFor(instrumentedType)).thenReturn(true); - Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedToken); + Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedSignatureToken); verify(methodRebaseResolver).asTokenMap(); verifyNoMoreInteractions(methodRebaseResolver); assertThat(specialMethodInvocation.isValid(), is(true)); @@ -147,7 +152,7 @@ public void testNonSpecializableRebaseMethodIsNotInvokable() throws Exception { when(resolution.getAdditionalArguments()).thenReturn(StackManipulation.Trivial.INSTANCE); when(rebasedMethod.isSpecializableFor(instrumentedType)).thenReturn(false); when(methodRebaseResolver.resolve(invokableMethod)).thenReturn(new MethodRebaseResolver.Resolution.Preserved(invokableMethod)); - Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedToken); + Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedSignatureToken); assertThat(specialMethodInvocation.isValid(), is(false)); }