-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Use StringBuilder in favor of StringBuffer #20035
Use StringBuilder in favor of StringBuffer #20035
Conversation
I think in all the cases that you changed, the |
I wouldn't call those remaining uses legitimate so much as required because Java never improved its APIs. The motivation for the change was a recent commit that I noticed after it was merged that added it. If I remove the forbidden aspect, then it will just happen again. |
There's nothing wrong with the usage in the recent commit that you noticed (I'm assuming it's the shard lock obtained failed exception change?) We need to keep the forbidden list small (until we can suppress a single method) and really for truly dangerous or abused methods. It's adding suppressions to those methods that bothers me, it just lets methods that should truly be forbidden slip in. |
That's fair. I'll remove the forbidden method aspect. Maybe we should have a separate, non-failing suggestion of "you should probably use". I don't think that |
Again, in the two cases that are left in this pull request, the JVM will elide the locks. The uses of |
I get that, but depending on a compiler optimization to make one class' code equivalent to another class is the wrong way to write and review code. Just use the right class, which is what this PR does. |
LGTM |
af3f135
to
e4ee966
Compare
This removes all instances of StringBuffer that are removeable. Uncontended synchronization in Java is pretty cheap, but it's unnecessary.
e4ee966
to
1cf694b
Compare
I fundamentally disagree with this. In fact, I disagree so strongly that I'm wondering if maybe you did not mean what you've said, or if you meant something different than how I'm interpreting it? I think it's critical to understand what the compiler and the runtime are doing, primarily for correctness, but also to understand where to rewrite code and where to not. For example, there's this little gem from the JLS (15.8.1):
And the OpenJDK compiler will do this using
The implication here is that there was something wrong with the previous uses and that's where I take issue: there was nothing wrong with the previous uses of The change is fine, we can make it, my point is that it doesn't matter though. |
I see value in this change from a consistency point of view. LGTM. |
++ for consistency |
This removes all instances of StringBuffer that are removeable
and marks the remaining usages as suppressed forbidden.Uncontended synchronization in Java is pretty cheap, but it's unnecessary in these cases.