-
Notifications
You must be signed in to change notification settings - Fork 668
Fix CreateAopProxyInterceptor in the Spring core-patch indeed changes the implementation of the Spring AOP proxy #739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import org.junit.runner.RunWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
| import org.springframework.aop.SpringProxy; | ||
| import org.springframework.aop.framework.AdvisedSupport; | ||
|
|
||
| import static org.hamcrest.core.Is.is; | ||
|
|
@@ -48,18 +49,69 @@ public void setUp() { | |
| } | ||
|
|
||
| @Test | ||
| public void testInterceptNormalObject() throws Throwable { | ||
| doReturn(Object.class).when(advisedSupport).getTargetClass(); | ||
| public void testInterceptClassImplementsNoInterfaces() throws Throwable { | ||
| // doReturn(Object.class).when(advisedSupport).getTargetClass(); | ||
| // doReturn(Object.class.getInterfaces()).when(advisedSupport).getProxiedInterfaces(); | ||
| assertThat(true, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, true))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testInterceptClassImplementsUserSuppliedInterface() throws Throwable { | ||
| doReturn(MockClassImplementsUserSuppliedInterface.class).when(advisedSupport).getTargetClass(); | ||
| doReturn(MockClassImplementsUserSuppliedInterface.class.getInterfaces()).when(advisedSupport).getProxiedInterfaces(); | ||
| assertThat(false, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testInterceptEnhanceInstanceObject() throws Throwable { | ||
| doReturn(MockClass.class).when(advisedSupport).getTargetClass(); | ||
| public void testInterceptClassImplementsSpringProxy() throws Throwable { | ||
| // doReturn(MockClassImplementsSpringProxy.class).when(advisedSupport).getTargetClass(); | ||
| // doReturn(MockClassImplementsSpringProxy.class.getInterfaces()).when(advisedSupport).getProxiedInterfaces(); | ||
| assertThat(true, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, true))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testInterceptClassImplementsEnhancedInstance() throws Throwable { | ||
| doReturn(MockClassImplementsEnhancedInstance.class).when(advisedSupport).getTargetClass(); | ||
| doReturn(MockClassImplementsEnhancedInstance.class.getInterfaces()).when(advisedSupport).getProxiedInterfaces(); | ||
| assertThat(true, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false))); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the answer in this SO thread, we basically should not expect classes that both use We are facing startup failures after upgrading to SkyWalking 9.4. |
||
| } | ||
|
|
||
| private class MockClass implements EnhancedInstance { | ||
| @Test | ||
| public void testClassImplementsEnhancedInstanceAndUserSuppliedInterface() throws Throwable { | ||
| doReturn(MockClassImplementsSpringProxyAndUserSuppliedInterface.class).when(advisedSupport).getTargetClass(); | ||
| doReturn(MockClassImplementsSpringProxyAndUserSuppliedInterface.class.getInterfaces()).when(advisedSupport).getProxiedInterfaces(); | ||
| assertThat(false, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testInterceptClassImplementsSpringProxyAndEnhancedInstance() throws Throwable { | ||
| doReturn(MockClassImplementsSpringProxyAndEnhancedInstance.class).when(advisedSupport).getTargetClass(); | ||
| doReturn(MockClassImplementsSpringProxyAndEnhancedInstance.class.getInterfaces()).when(advisedSupport).getProxiedInterfaces(); | ||
| assertThat(true, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testInterceptClassImplementsSpringProxyAndUserSuppliedInterface() throws Throwable { | ||
| doReturn(MockClassImplementsSpringProxyAndUserSuppliedInterface.class).when(advisedSupport).getTargetClass(); | ||
| doReturn(MockClassImplementsSpringProxyAndUserSuppliedInterface.class.getInterfaces()).when(advisedSupport).getProxiedInterfaces(); | ||
| assertThat(false, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testInterceptClassImplementsEnhancedInstanceAndUserSuppliedInterface() throws Throwable { | ||
| doReturn(MockClassImplementsEnhancedInstanceAndUserSuppliedInterface.class).when(advisedSupport).getTargetClass(); | ||
| doReturn(MockClassImplementsEnhancedInstanceAndUserSuppliedInterface.class.getInterfaces()).when(advisedSupport).getProxiedInterfaces(); | ||
| assertThat(false, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testInterceptClassImplementsSpringProxyAndEnhancedInstanceAndUserSuppliedInterface() throws Throwable { | ||
| doReturn(MockClassImplementsSpringProxyAndEnhancedInstanceAndUserSuppliedInterface.class).when(advisedSupport).getTargetClass(); | ||
| doReturn(MockClassImplementsSpringProxyAndEnhancedInstanceAndUserSuppliedInterface.class.getInterfaces()).when(advisedSupport).getProxiedInterfaces(); | ||
| assertThat(false, is(interceptor.afterMethod(enhancedInstance, null, new Object[] {advisedSupport}, new Class[] {Object.class}, false))); | ||
| } | ||
|
|
||
| private class MockClassImplementsEnhancedInstance implements EnhancedInstance { | ||
|
|
||
| @Override | ||
| public Object getSkyWalkingDynamicField() { | ||
|
|
@@ -72,4 +124,81 @@ public void setSkyWalkingDynamicField(Object value) { | |
| } | ||
| } | ||
|
|
||
| private class MockClassImplementsUserSuppliedInterface implements UserSuppliedInterface { | ||
|
|
||
| @Override | ||
| public void methodOfUserSuppliedInterface() { | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| private class MockClassImplementsSpringProxy implements SpringProxy { | ||
|
|
||
| } | ||
|
|
||
| private class MockClassImplementsSpringProxyAndEnhancedInstance implements EnhancedInstance, SpringProxy { | ||
|
|
||
| @Override | ||
| public Object getSkyWalkingDynamicField() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setSkyWalkingDynamicField(Object value) { | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| private class MockClassImplementsEnhancedInstanceAndUserSuppliedInterface implements EnhancedInstance, UserSuppliedInterface { | ||
|
|
||
| @Override | ||
| public Object getSkyWalkingDynamicField() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setSkyWalkingDynamicField(Object value) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void methodOfUserSuppliedInterface() { | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private class MockClassImplementsSpringProxyAndUserSuppliedInterface implements SpringProxy, UserSuppliedInterface { | ||
|
|
||
| @Override | ||
| public void methodOfUserSuppliedInterface() { | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private class MockClassImplementsSpringProxyAndEnhancedInstanceAndUserSuppliedInterface implements EnhancedInstance, SpringProxy, UserSuppliedInterface { | ||
|
|
||
| @Override | ||
| public Object getSkyWalkingDynamicField() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setSkyWalkingDynamicField(Object value) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void methodOfUserSuppliedInterface() { | ||
| } | ||
|
|
||
| } | ||
|
|
||
| interface UserSuppliedInterface { | ||
|
|
||
| void methodOfUserSuppliedInterface(); | ||
|
|
||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is
SpringProxy.classadded into the hierarchy tree?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review.
As shown below, the
hasNoUserSuppliedProxyInterfacesmethod inDefaultAopProxyFactoryis defined as follows:spring4/spring5
spring3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this seems ok. Could you update the changelog? Then I could merge this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review.
The
Changes.mdfile has been updated.