Skip to content
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

Cannot modify visibility of private method? #1728

Open
facboy opened this issue Nov 22, 2024 · 7 comments
Open

Cannot modify visibility of private method? #1728

facboy opened this issue Nov 22, 2024 · 7 comments
Assignees
Labels
Milestone

Comments

@facboy
Copy link

facboy commented Nov 22, 2024

Is the following not supposed to work (in an AgentBuilder)?

return dynamicTypeBuilder
        .method(methodMatcher)
        .intercept(SuperMethodCall.INSTANCE)
        .transform(Transformer.ForMethod.withModifiers(Visibility.PROTECTED));

It's a bit hard to follow but when debugging it is applied to the transformed MethodDescriptor but this is then added to a Prepared.Entry which has its own visibility field. The visibility field gets its value from the original methodDescriptor and ignores modifiers on the transformed MethodDescriptor.

@raphw
Copy link
Owner

raphw commented Nov 23, 2024

Have a look at ModifierAdjustment which can be applied as a decorator (without defining an interception). I think that is what you actually want to do.

@raphw raphw self-assigned this Nov 23, 2024
@raphw raphw added the question label Nov 23, 2024
@raphw raphw added this to the 1.15.10 milestone Nov 23, 2024
@facboy
Copy link
Author

facboy commented Nov 23, 2024

hmm...so at runtime, once adjusted, i can see that the modifier has changed, but it still doesn't do quite what i wanted, so i guess i'll ask another question:

is it possible to change a method from private to protected, and then have (existing) subclasses override that method?

@raphw
Copy link
Owner

raphw commented Nov 24, 2024

That should be possible, yes. This does however assume that both methods have the same signature.

What are you observing?

@facboy
Copy link
Author

facboy commented Nov 24, 2024

I can see with reflection that the modifier is changed, but the calling methods just invoke the "previously private but now protected" method directly and ignore the overriding methods in the sub-classes.

@raphw
Copy link
Owner

raphw commented Nov 24, 2024 via email

@facboy
Copy link
Author

facboy commented Nov 24, 2024

hum, i tried recreating in an isolated test case and haven't been able to, so perhaps i've got some mismatch in the arguments or something somewhere. when you say already linked what do you mean? the classes are already loaded somehow? or?

@raphw
Copy link
Owner

raphw commented Nov 25, 2024

For example: if a class path scanner looks for classes, this might trigger their loading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants