Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 516530

Summary: Use StringBuilder instead of StringBuffer in eclipse.platform.ui for simple declarations
Product: [Eclipse Project] Platform Reporter: Lars Vogel <Lars.Vogel>
Component: UIAssignee: Lars Vogel <Lars.Vogel>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: akurtakov, Lars.Vogel, loskutov
Version: 4.4   
Target Milestone: 4.8 M1   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/96878
https://git.eclipse.org/r/96879
https://git.eclipse.org/r/96880
https://git.eclipse.org/r/96881
https://git.eclipse.org/r/96882
https://git.eclipse.org/r/96883
https://git.eclipse.org/r/96884
https://git.eclipse.org/r/96885
https://git.eclipse.org/r/98760
https://git.eclipse.org/r/98773
https://git.eclipse.org/r/98838
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=6bab612a4fd7a00332afe4412441db9ad0b15b36
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=40f668c37e090b537aeaf67456b348ba96ce690c
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=a2def5476b0222c7fee40a304fee36f0d29119ee
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=c42709d2e2893a355d9c654f67301dc349e56ef0
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=da2e408f6ecdeb2019c2298b4372097d60dc7c92
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=10e998f40b0111726cf2825cf6876d59d5f47025
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=3576da2e8ef94ed2c06ccf4131f66fef603accb5
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=cf36064add4e55307816544b05d0d230aeaefcad
https://git.eclipse.org/r/101138
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=2a1936a0f33c26c9939fcd17184a709e4177b675
Whiteboard:
Bug Depends on:    
Bug Blocks: 516844    

Description Lars Vogel CLA 2017-05-11 15:13:33 EDT
See http://stackoverflow.com/questions/355089/difference-between-stringbuilder-and-stringbuffer

Unless we use StringBuffer in API or have a good reason, I suggest to change to StringBuilder.
Comment 1 Eclipse Genie CLA 2017-05-11 15:15:08 EDT
New Gerrit change created: https://git.eclipse.org/r/96878
Comment 2 Eclipse Genie CLA 2017-05-11 15:15:29 EDT
New Gerrit change created: https://git.eclipse.org/r/96879
Comment 3 Eclipse Genie CLA 2017-05-11 15:15:51 EDT
New Gerrit change created: https://git.eclipse.org/r/96880
Comment 4 Eclipse Genie CLA 2017-05-11 15:16:12 EDT
New Gerrit change created: https://git.eclipse.org/r/96881
Comment 5 Eclipse Genie CLA 2017-05-11 15:16:33 EDT
New Gerrit change created: https://git.eclipse.org/r/96882
Comment 6 Eclipse Genie CLA 2017-05-11 15:16:54 EDT
New Gerrit change created: https://git.eclipse.org/r/96883
Comment 7 Eclipse Genie CLA 2017-05-11 15:17:05 EDT
New Gerrit change created: https://git.eclipse.org/r/96884
Comment 8 Eclipse Genie CLA 2017-05-11 15:17:16 EDT
New Gerrit change created: https://git.eclipse.org/r/96885
Comment 9 Thomas Schindl CLA 2017-05-11 15:26:49 EDT
In general i think it is ok - i briefly looked at the cases although and think in most of them the jit optimizes away the locks because it understands the single thread nature
Comment 10 Lars Vogel CLA 2017-05-11 15:31:35 EDT
(In reply to Thomas Schindl from comment #9)
> In general i think it is ok - i briefly looked at the cases although and
> think in most of them the jit optimizes away the locks because it
> understands the single thread nature

AFAIK JIT will only get active after a relative high number of invocations. Therefore using the faster API should give us some speed improvements.
Comment 11 Andrey Loskutov CLA 2017-05-17 17:16:39 EDT
I've already commented this on JDT bug and I would simply repeat it here:

Lars, please, this makes no sense to change for tests, except you wastes your and other time and makes the history changes that hide the real ones. 

I would also say that mass change for not performance critical production code is conter-productive and will only disturb others from work and make tracking history changes impossible. A big -1 from me.

No mass changes, and only change in places where we know about performance bottle necks caused by StringBuffer.
Comment 12 Lars Vogel CLA 2017-05-17 17:19:28 EDT
(In reply to Andrey Loskutov from comment #11)

See my reply in Bug 516844. I have warnings in my code for this as I'm using SonarLint. Also AFAIK StringBuilder should be preferred compared to StringBuilder in code and updating our code basis to modern constructs is IMHO important.
Comment 13 Lars Vogel CLA 2017-05-17 17:20:42 EDT
(In reply to Lars Vogel from comment #12)
> (In reply to Andrey Loskutov from comment #11)
> 
> See my reply in Bug 516844. I have warnings in my code for this as I'm using
> SonarLint. Also AFAIK StringBuilder should be preferred compared to
> StringBuilder in code and updating our code basis to modern constructs is
> IMHO important.

Andrey, remember the unnecessary trailing whitespace issues which affected you, which we solved with mass changes?
Comment 14 Andrey Loskutov CLA 2017-05-17 17:27:21 EDT
(In reply to Lars Vogel from comment #13)
> (In reply to Lars Vogel from comment #12)
> > (In reply to Andrey Loskutov from comment #11)
> > 
> > See my reply in Bug 516844. I have warnings in my code for this as I'm using
> > SonarLint. Also AFAIK StringBuilder should be preferred compared to
> > StringBuilder in code and updating our code basis to modern constructs is
> > IMHO important.
> 
> Andrey, remember the unnecessary trailing whitespace issues which affected
> you, which we solved with mass changes?

The difference is that Git can ignore white space changes, but can't do this for anything else. This is a big issue if you are trying undrestand the reason behind the otherwise undocumented code.
Comment 15 Lars Vogel CLA 2017-05-17 17:30:14 EDT
(In reply to Andrey Loskutov from comment #14)

> The difference is that Git can ignore white space changes, but can't do this
> for anything else. This is a big issue if you are trying undrestand the
> reason behind the otherwise undocumented code.

Take a look at some of the changed lines in my Gerrit. Most of them are StringBuilder/StringBuffer var = new StringBuilder/StringBuffer. I doubt that you will use these lines to identify bugs.
Comment 16 Andrey Loskutov CLA 2017-05-19 05:13:40 EDT
(In reply to Lars Vogel from comment #15)
> (In reply to Andrey Loskutov from comment #14)
> 
> > The difference is that Git can ignore white space changes, but can't do this
> > for anything else. This is a big issue if you are trying undrestand the
> > reason behind the otherwise undocumented code.
> 
> Take a look at some of the changed lines in my Gerrit. Most of them are
> StringBuilder/StringBuffer var = new StringBuilder/StringBuffer. I doubt
> that you will use these lines to identify bugs.

Agree, if you can guarantee that the patches only touch cases where only one line with default StringBuffer constructor without arguments is affected (e.g. not a nested call as argument to another function etc). 

So StringBuffer var = new StringBuffer() is OK, but NOT for 
StringBuffer var = new StringBuffer(42) or callMe(new StringBuffer("42")) etc
Comment 17 Lars Vogel CLA 2017-05-19 06:18:53 EDT
(In reply to Andrey Loskutov from comment #16)

> So StringBuffer var = new StringBuffer() is OK, but NOT for 
> StringBuffer var = new StringBuffer(42) or callMe(new StringBuffer("42")) etc

Sounds like a good starting point. Lets use this bug for this work and revisit the more complex work with more complex bug reports.
Comment 18 Eclipse Genie CLA 2017-06-07 04:51:31 EDT
New Gerrit change created: https://git.eclipse.org/r/98760
Comment 19 Eclipse Genie CLA 2017-06-07 05:56:03 EDT
New Gerrit change created: https://git.eclipse.org/r/98773
Comment 20 Eclipse Genie CLA 2017-06-07 16:22:34 EDT
New Gerrit change created: https://git.eclipse.org/r/98838
Comment 29 Alexander Kurtakov CLA 2017-07-04 02:40:40 EDT
All patches are in can we close it?
Comment 30 Lars Vogel CLA 2017-07-04 02:47:42 EDT
(In reply to Alexander Kurtakov from comment #29)
> All patches are in can we close it?

Thanks, Alex for the review and merges.