-
Notifications
You must be signed in to change notification settings - Fork 25
Fix Proxy Generation with Final Methods #896
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
Conversation
Fixes issue where we would try to generate proxies for classes with final methods
This reverts commit 5658f50.
Hmm, so currently when moving the test into blackbox-test-inject, it won't compile as it generates the following method: @Override
protected int next(int arg0) {
return onceProvider.get().next(arg0);
} ... which is a protected method, so wanting the use of |
I see |
Actually I don't see, because when I move it to blackbox it doesn't fail.
to borrow a phrase from my stance on social media, "I don't follow". we don't want the super, we want to call the actual implementation stored in |
So when it's: @Bean
public Random secureRandom() {
return new SecureRandom();
} Then it becomes a ...
var factory = builder.get(RandomFactory.class);
builder.registerLazy(() -> {
return factory.secureRandom();
}, Random$Lazy::new); } ... but with SecureRandom its just a lazy [beanReader.lazy()] ... so no var factory = builder.get(RandomFactory.class);
builder.registerProvider(() -> {
return factory.secureRandom();
}); |
well, it appears the bigger problem is situations where the no-arg constructor calls the methods. I'll just an escape hatch to disable proxy generation |
Ah, but a |
That's exactly right, it's the old behavior if you set that flag to false. In the case of random it doesn't appear that we can cleanly lazy it with a proxy. |
…xception with the inline comment: `@Lazy` proxy does not support protected methods, instead use @lazy(useProxy = false)
@SentryMan review the last commit c0ecf8f .... that will generate protected methods that throw UnsupportedOperationException like: @Override
protected int next(int arg0) {
// @Lazy proxy does not support protected methods, instead use @Lazy(useProxy = false)
throw new UnsupportedOperationException();
} Without this, user will instead get a compilation error which I think will confuse them so I think this might be better? |
I mean in the first place the generated classes are final so the generated protected methods cannot be accessed |
Technically they are accessible by classes in the same package as the generated lazy class ... but that does require specific use of the So yeah, if you are happy with that last commit we can look to merge this etc. |
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.
Lgtm
Actually one sec |
okay good with this |
Fixes issue where we would try to generate proxies for classes with final methods.
resolves #895