SONARJAVA-5493 Implement check for uses of ClassFile.build instead of transformClass#5222
Merged
romainbrenguier merged 13 commits intomasterfrom Jul 2, 2025
Merged
SONARJAVA-5493 Implement check for uses of ClassFile.build instead of transformClass#5222romainbrenguier merged 13 commits intomasterfrom
romainbrenguier merged 13 commits intomasterfrom
Conversation
d45319e to
6db7667
Compare
| return new TreeMatcher<>(predicate.or(other.predicate)); | ||
| } | ||
|
|
||
| public void setPredicate(Predicate<T> newPredicate) { |
Contributor
There was a problem hiding this comment.
I prefer if we keep the predicate immutable. What do you think about it?
Contributor
Author
There was a problem hiding this comment.
Totally agree, but it was not trivial. I think I got a decent solution with the recursive factory.
| } | ||
|
|
||
| public static TreeMatcher<Tree> statementAt(int index, TreeMatcher<StatementTree> statementMatcher) { | ||
| return new TreeMatcher<>(tree -> ((tree instanceof BlockTree block && statementMatcher.check(block.body().get(index))) |
Contributor
There was a problem hiding this comment.
I think it would be good to add a test with out of bound index
This commit was generated by a kotlin script.
6db7667 to
95ead3e
Compare
95ead3e to
c3e8f8e
Compare
erwan-serandour
approved these changes
Jul 2, 2025
| public static void transformClassFile(Path path) throws IOException { | ||
| ClassFile classFile = ClassFile.of(); | ||
| ClassModel classModel = classFile.parse(path); | ||
| byte[] newBytes = classFile.build( // Noncompliant |
Contributor
There was a problem hiding this comment.
I think testing the message at least one time would be good
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.




SONARJAVA-5493