You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/02/10 06:37:10 UTC
[GitHub] [skywalking] adaivskenan opened a new issue #8532: [Bug] No default constructor found. #622 Not fully resolved
adaivskenan opened a new issue #8532:
URL: https://github.com/apache/skywalking/issues/8532
### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/skywalking/issues?q=is%3Aissue) and found no similar issues.
### Apache SkyWalking Component
Java Agent (apache/skywalking-java)
### What happened
No default constructor found Exception occurs When a class has only one private constructor with parameters. I have checked the [No default constructor found. #622](https://github.com/apache/skywalking/issues/622) .There is still a bug here, Spring supports private constructors by default, but when I use agent get a No default constructor found Exception.
The following is an analysis of the cause of the problem:
`org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor#determineCandidateConstructors`
use `java.lang.Class#getDeclaredConstructors` to get declared constructors(These are public, protected, default (package) access, and private constructors) . But, `org.apache.skywalking.apm.plugin.spring.patch.AutowiredAnnotationProcessorInterceptor` ignored the private constructors.
### What you expected to happen
Spring supports private constructors by default, I think skywalking agent should support this too.
### How to reproduce
The example code is as follows:
```java
@RestController
public class TestNoConstructor {
private final TestService testService;
// use private constructor with one parameter
private TestNoConstructor(TestService testService) {
this.testService = testService;
}
}
```
### Anything else
_No response_
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] wu-sheng commented on issue #8532: [Bug] No default constructor found. #622 Not fully resolved
Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #8532:
URL: https://github.com/apache/skywalking/issues/8532#issuecomment-1034624451
OK, this is rare to see in practice. But I am not sure what is a good way to check whether this private constructor is yours or not. Do you have any suggestions? Maybe check the type of constructor's parameter?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] wu-sheng commented on issue #8532: [Bug] No default constructor found. #622 Not fully resolved
Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #8532:
URL: https://github.com/apache/skywalking/issues/8532#issuecomment-1041235854
@adaivskenan Could you send a pull request to share which way you chose to skip the agent-created constructor? If it is widely suitable, I am good to have that in the upstream.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] wu-sheng closed issue #8532: [Bug] No default constructor found. #622 Not fully resolved
Posted by GitBox <gi...@apache.org>.
wu-sheng closed issue #8532:
URL: https://github.com/apache/skywalking/issues/8532
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] adaivskenan commented on issue #8532: [Bug] No default constructor found. #622 Not fully resolved
Posted by GitBox <gi...@apache.org>.
adaivskenan commented on issue #8532:
URL: https://github.com/apache/skywalking/issues/8532#issuecomment-1034676369
Currently, I have informed my colleague not to write controller like this. I am not familiar with the mechanism of `AutowiredAnnotationProcessorInterceptor`, and I think the way the constructor parameters are checked is tricky, but i don not have a better way yet.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] adaivskenan commented on issue #8532: [Bug] No default constructor found. #622 Not fully resolved
Posted by GitBox <gi...@apache.org>.
adaivskenan commented on issue #8532:
URL: https://github.com/apache/skywalking/issues/8532#issuecomment-1034614119
skywalking java agent : v8.7.0
springboot version: 2.4.6
When I use skywalking java agent, my project start failed. I found that when a controller has only one private constructor with parameters, the problem can be reproduced. I think the reason is agent ignored the constructor without distinguish whether the constructor is custom or by interceptor fill out. [AutowiredAnnotationProcessorInterceptor](https://github.com/apache/skywalking-java/blob/main/apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/AutowiredAnnotationProcessorInterceptor.java)(line 75, `if (!Modifier.isPrivate(constructor.getModifiers())) {`)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] wallezhang commented on issue #8532: [Bug] No default constructor found. #622 Not fully resolved
Posted by GitBox <gi...@apache.org>.
wallezhang commented on issue #8532:
URL: https://github.com/apache/skywalking/issues/8532#issuecomment-1035945281
@adaivskenan I think the problem is that Spring didn't recognize this private constructor. Maybe you can try to upgrade your spring boot to 2.5.x. `AutowiredAnnotationProcessorInterceptor` will give priority to constructors recognized by Spring. Only when Spring does not recognize the constructor, `AutowiredAnnotationProcessorInterceptor` will analyze the constructor of the current class and ignore the private one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] wu-sheng commented on issue #8532: [Bug] No default constructor found. #622 Not fully resolved
Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #8532:
URL: https://github.com/apache/skywalking/issues/8532#issuecomment-1034552072
What do you propose? I am sorry, I read your description, and can't follow the case. The issue was from old history(3.2.x), I think we have a conflict patch plugin for that case already. But what is your case?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking] adaivskenan commented on issue #8532: [Bug] No default constructor found. #622 Not fully resolved
Posted by GitBox <gi...@apache.org>.
adaivskenan commented on issue #8532:
URL: https://github.com/apache/skywalking/issues/8532#issuecomment-1041231941
@wallezhang The problem still exists after upgrading the SpringBoot version, Thank you for explaining the mechanism of AutowiredAnnotationProcessorInterceptor. If no agent is used, Spring can identify the constructor, and the condition is `rawCandidates.length == 1 && rawCandidates[0].getParameterCount() > 0`. If the agent is used, the rawCandidates will become 2 (including the one created by skywalking java agent), and Spring will have no conditions that can be met to recognize the constructor. [AutowiredAnnotationBeanPostProcessor](https://github.com/spring-projects/spring-framework/blob/5.3.x/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java)](line 375).
I think `AutowiredAnnotationProcessorInterceptor` should ignored the constructor created by skywalking java agent by judging where the constructor is synthetic or not @wu-sheng . And I tried this solution, it works.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org