Hi Gary, On 14.12.2024 17:45, Gary Gregory wrote:
What passes the criteria of "simple cases"?
I would classify all sequences of `new StringBuilder()`, `append` and `toString` without any branching or loops as simple cases.
Should this be enforced or can it be enforced? With Checkstyle? Somethings else?
This can be enforced by running the OpenRewrite rule I mentioned before[1] on a regular basis and check that nothing was actually rewritten.
The only problem with applying OpenRewrite rule is that they can break the formatting of the source code. Do we have an automated way to reformat the source code to conform to the CheckStyle rules?
[1] https://docs.openrewrite.org/recipes/staticanalysis/replacestringbuilderwithstring
Considering: - that we support Java 8 and up to the current version. - that we don't say which Java vendor we support. - that the JLS (which version...) only suggests that a vendor could implement string concatenation using one of the Java stock classes. Is there a risk that changing to not using our unsynchronized class have performance side-effects?
There is no bytecode equivalent to string concatenation, so it is up to the compiler to translate string concatenations in methods calls. If you compile for Java 8 you'll end up using `StringBuilder`. If you compile for Java 9 or higher, you'll end up with a specialized lambda.
Piotr