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

support bootstrap method coping when using code coping #480

Merged
merged 1 commit into from May 3, 2024

Conversation

likey3
Copy link

@likey3 likey3 commented Jan 18, 2024

Hello, I'm using javassist recently, and I really like the function it provides to copy methods, this makes it very convenient for me to copy the specified method to the target method without having to worry about bytecode writing.

However, during use, it was found that if the method contains lambda expressions or the simple string concatenation(after jdk>=9,after JDK 9, because string concatenation uses BootstrapMethods), it will cause compilation errors or runtime errors.
I looked through the relevant information but not much. I also saw someone mentioning issue(#388 ) related to this.

Cause:

I looked at the source code myself and found that when copying the invoke dynamic operator, only the data of the constant pool was copied, and the bootstrap method was not copied.This will cause errors if there is no corresponding bootstrap method in the target class.

Solution:

When copying the invoke dynamic operator, find the bootstrap method based on the bootstrap method index in the source class and overwrite or add the bootstrap method to the new bootstrap method index in the destination class. In order to prevent the loss of static methods generated by some lambdas, after copying the bootstrap method, the static methods referenced in the source class are also copied to the target class.

I have personally evaluated the new code and it should not affect other operations, and it provides great convenience when using the code copy function. but I am not sure whether it violates the design intention of javassist. Thanks for the discussion and review.

@chibash chibash merged commit 204d678 into jboss-javassist:master May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants