You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Shevek (JIRA)" <ji...@apache.org> on 2012/09/27 09:30:09 UTC

[jira] [Created] (LANG-833) ToStringBuilder should use StringBuilder

Shevek created LANG-833:
---------------------------

             Summary: ToStringBuilder should use StringBuilder
                 Key: LANG-833
                 URL: https://issues.apache.org/jira/browse/LANG-833
             Project: Commons Lang
          Issue Type: Bug
          Components: lang.*
    Affects Versions: 3.1
            Reporter: Shevek


Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.

Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13464947#comment-13464947 ] 

Sebb commented on LANG-833:
---------------------------

Also ReflectionToStringBuilder
                
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Adrian Shum (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13476684#comment-13476684 ] 

Adrian Shum commented on LANG-833:
----------------------------------

Support for using StringBuilder in ToStringBuilder.  I believe lang3 allow breaking certain level of backward compatibility (and afaik it did).  And, most important is, the suggested usage of ToStringBuilder is mostly for a short-lived string building that is rarely shared between threads.  

A compromise can be allowing an (optional) extra ctor argument in ToStringBuilder to denote whether we want it to be thread-safe or not (we can keep the default as thread-safe).  Internally, instead of using StringBuffer/StringBuilder directly, declare buffer as AbstractStringBuilder instead (which is the parent of StringBuffer and StringBuilder).  Instantiate StringBuffer or StringBuilder according to the ctor argument.

For people who want better performance, they can just explicitly change the usage of ToStringBuilder from new ToStringBuilder(....) to new ToSTringBuilder(..., THREAD_UNSAFE).  

Sounds feasible to me.  :P
                
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13464649#comment-13464649 ] 

Sebb commented on LANG-833:
---------------------------

I don't think it makes sense to use StrBuilder in the API, but for internal-only use that would be OK where sync is not needed.

There may be some methods which would benefit from using AbstractStringBuilder so the user could provide either.
But this needs to be done without breaking the API and thread-safety guarantees.
                
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13464850#comment-13464850 ] 

Sebb commented on LANG-833:
---------------------------

Actually, one cannot use AbstractStringBuilder as that is not visible.

The problem is twofold:
- there's no suitable common interface or class for StringBuilder and StringBuffer
- changing to use StringBuilder would break compatibility, and might cause some applications that rely on the sync. to fail

I don't see how it's possible to use StringBuilder without either:
- breaking compatibility and some apps, OR
- duplicating the API
                
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Shevek (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13464872#comment-13464872 ] 

Shevek commented on LANG-833:
-----------------------------

I did the same analysis and I agree with it. That's why I called it a "missed opportunity" on the change to lang3.
                
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13464619#comment-13464619 ] 

Sebb edited comment on LANG-833 at 10/16/12 8:46 AM:
-----------------------------------------------------

bq. No cause for it. [i.e. StringBuffer]

StringBuffer may still be needed for synchronisation purposes.

Also if used in APIs, it may not be possible to change to StringBuilder without breaking compatibility.

But if it is possible to replace Buffer with Builder it would be sensible to do so.
                
      was (Author: sebb@apache.org):
    bq. No cause for it. [i.e. StringBuffer]

StringBuffer may still be needed for snchronisation purposes.

Also if used in APIs, it may not be possible to change to StringBuilder without breaking compatibility.

But if it is possible to replace Buffer with Builder it would be sensible to do so.
                  
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Adrian Shum (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13476684#comment-13476684 ] 

Adrian Shum edited comment on LANG-833 at 10/16/12 2:59 AM:
------------------------------------------------------------

Support for using StringBuilder in ToStringBuilder.  I believe lang3 allow breaking certain level of backward compatibility (and afaik it did).  And, most important is, the suggested usage of ToStringBuilder is mostly for a short-lived string building that is rarely shared between threads.  

A compromise can be achieved (though I don't think it is really needed :P) is by allowing an (optional) extra ctor argument in ToStringBuilder to denote whether we want it to be thread-safe or not (we can keep the default as thread-safe).  Internally, instead of using StringBuffer/StringBuilder directly, declare buffer as AbstractStringBuilder instead (which is the parent of StringBuffer and StringBuilder).  Instantiate StringBuffer or StringBuilder according to the ctor argument.

For people who want better performance, they can just explicitly change the usage of ToStringBuilder from new ToStringBuilder(....) to new ToSTringBuilder(..., THREAD_UNSAFE).  

Sounds feasible to me.  :P
                
      was (Author: adrianshum):
    Support for using StringBuilder in ToStringBuilder.  I believe lang3 allow breaking certain level of backward compatibility (and afaik it did).  And, most important is, the suggested usage of ToStringBuilder is mostly for a short-lived string building that is rarely shared between threads.  

A compromise can be allowing an (optional) extra ctor argument in ToStringBuilder to denote whether we want it to be thread-safe or not (we can keep the default as thread-safe).  Internally, instead of using StringBuffer/StringBuilder directly, declare buffer as AbstractStringBuilder instead (which is the parent of StringBuffer and StringBuilder).  Instantiate StringBuffer or StringBuilder according to the ctor argument.

For people who want better performance, they can just explicitly change the usage of ToStringBuilder from new ToStringBuilder(....) to new ToSTringBuilder(..., THREAD_UNSAFE).  

Sounds feasible to me.  :P
                  
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Shevek (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13464826#comment-13464826 ] 

Shevek commented on LANG-833:
-----------------------------

The point of using StringBuilder is twofold: Firstly for performance; whoever needed a threadsafe toString method, and anybody who does can synchronize themselves. It's not as if synchronization within ToStringBuilder is capable of guarding access to an instance variable.

Secondly, for compatibility with existing APIs which are capable of appending to a java.lang.StringBuilder, which is the majority, these days. That's the killer for me.
                
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13476860#comment-13476860 ] 

Sebb commented on LANG-833:
---------------------------

bq.  I believe lang3 allow breaking certain level of backward compatibility (and afaik it did).

Releases of Lang must be binary compatible.
We did break binary compatibility when with Lang3, however that was done by changing package name (and Maven coords) so code which still relies on the old API does not break. 
Code that wants to move to Lang3 has to be editted to use the new package name.
Further compat. breaks would require creating Lang4/changing package name again, so is not to be undertaken lightly.

bq. declare buffer as AbstractStringBuilder instead

Have you tried this?
AbstractStringBuilder is package-protected, so cannot be used outside the JVM.

If you can provide a patch that solves the issue without breaking binary compatibility, please attach it to this issue.
                
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13464619#comment-13464619 ] 

Sebb commented on LANG-833:
---------------------------

bq. No cause for it. [i.e. StringBuffer]

StringBuffer may still be needed for snchronisation purposes.

Also if used in APIs, it may not be possible to change to StringBuilder without breaking compatibility.

But if it is possible to replace Buffer with Builder it would be sensible to do so.
                
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13464648#comment-13464648 ] 

Gary D. Gregory commented on LANG-833:
--------------------------------------

Or our own StrBuilder.
                
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13464855#comment-13464855 ] 

Sebb commented on LANG-833:
---------------------------

Unfortunately, the Appendable interface throws IOException which does not help.
                
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13464943#comment-13464943 ] 

Sebb commented on LANG-833:
---------------------------

ToStringStyle would also need to be converted/duplicated
                
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (LANG-833) ToStringBuilder should use StringBuilder

Posted by "Sebb (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-833?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb updated LANG-833:
----------------------

    Issue Type: Improvement  (was: Bug)

Not a bug; it's a possible enhancement for a future version.
                
> ToStringBuilder should use StringBuilder
> ----------------------------------------
>
>                 Key: LANG-833
>                 URL: https://issues.apache.org/jira/browse/LANG-833
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Shevek
>
> Rewriting as lang3 but still using StringBuffer (synchronized) looks like a missed opportunity. Please use StringBuilder.
> Suggest audit for uses of StringBuffer in lang3 overall. No cause for it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira