On Sat, Dec 14, 2024 at 1:56 PM Piotr P. Karwasz
<pi...@mailing.copernik.eu> wrote:
>
> 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.

Sounds reasonable. Maybe "no control flow" is "simple".

>
> > 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?

We do not. I use Eclipse, and some components have an
Eclipse-formatted XML config file. This is not great and not as good
as something like Spotless, which is used nowhere in Commons. It could
be introduced in commons-parent.

Gary

>
> [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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to