-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
String concatenation visitor: fix for ArrayIndexOutOfBoundsException #427
Conversation
@jpstotz thank you for fix! |
test: simple JUnit test cases added for testing StringBuilder chain processing (chains that can be and that can't be simplified)
@skylot You are right, JUnit test cases are a good thing. It turned out that I had a major misunderstanding regarding the visitor code which ended up it totally defect code created by it. After creating the matching unit test I understand it much better. I think I have covered the major cases with the unit test. I wasn't sure where to put the unit test (which package). Therefore feel free to move it where you think it belongs to. |
@@ -201,7 +204,15 @@ private static InsnNode convertInvoke(MethodNode mth, InsnNode insn) { | |||
} | |||
|
|||
for (; argInd < len; argInd++) { // Add the .append(xxx) arg string to concat | |||
concatInsn.addArg(chain.get(argInd).getArg(1)); | |||
InsnNode node = chain.get(argInd); | |||
MethodInfo method = ((CallMthInterface) node).getCallMth(); |
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.
Add instanceof
check before the cast, it will make code much safer.
And next time instead of merging just rebase your commits on latest master, also fix for the previous commit is better to squash together, so you will get 2 nice commits on top of master :)
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.
The missing instanceof
check is on purpose. If we encounter such a case most likely can't simplify the chain. It will then raise an Exception so that anybody may notice it and we can take a closer look onto it. Therefore the effect is the same the only difference is that without the instanceof check nothing is logged.
Rebase: According what I have read you should not do this once you have pushed your commits to a public repo. And as the branch this PR bases on is public...
Therefore I will keep on using git as I do - at least most of the times it does what I want.
If they develop such a complex version control system they should make it more usable and intuitive to use.
🎉 This PR is included in version 0.9.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
My log file was often very polluted by the string concatenation converter throwing ArrayIndexOutOfBoundsException when the StringBuilder chain contains calls not only to and append but also to
toString()
or any other method of StringBuilder that does not take an argument.This pull request limit the chain to process only constructor class and calls to append.