support bootstrap method coping when using code coping #480
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.
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.