[jira] [Created] (LANG-784) Strange behavior on StringUtils.difference

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (LANG-784) Strange behavior on StringUtils.difference

ASF GitHub Bot (Jira)
Strange behavior on StringUtils.difference
------------------------------------------

                 Key: LANG-784
                 URL: https://issues.apache.org/jira/browse/LANG-784
             Project: Commons Lang
          Issue Type: Improvement
          Components: lang.*
    Affects Versions: 3.0.1
            Reporter: Arnaud BRUNET
            Priority: Minor


Hi,

The behavior of the method StringUtils.difference () behaves in a non-intuitive (explain in the javadoc).

StringUtils.difference ("abc", "") returns "" as intuitively expected to be "abc".

Is it possible to change this behavior ?

Regards,
Arnaud

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (LANG-784) Strange behavior on StringUtils.difference

ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13179594#comment-13179594 ]

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

The Javadoc is clear IMO:

{quote}
Compares two Strings, and returns the portion where they differ.
(More precisely, return the remainder of the second String,
starting from where it's different from the first.
{quote}

A piece of the 2nd String is always returned, in this case a piece of "".

Also note this example:

StringUtils.difference("", "abc") = "abc"
               

> Strange behavior on StringUtils.difference
> ------------------------------------------
>
>                 Key: LANG-784
>                 URL: https://issues.apache.org/jira/browse/LANG-784
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.0.1
>            Reporter: Arnaud BRUNET
>            Priority: Minor
>
> Hi,
> The behavior of the method StringUtils.difference () behaves in a non-intuitive (explain in the javadoc).
> StringUtils.difference ("abc", "") returns "" as intuitively expected to be "abc".
> Is it possible to change this behavior ?
> Regards,
> Arnaud

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (LANG-784) Strange behavior on StringUtils.difference

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13179854#comment-13179854 ]

Arnaud BRUNET commented on LANG-784:
------------------------------------

I have seeing the javadoc but it's still non-intuitive.
               

> Strange behavior on StringUtils.difference
> ------------------------------------------
>
>                 Key: LANG-784
>                 URL: https://issues.apache.org/jira/browse/LANG-784
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.0.1
>            Reporter: Arnaud BRUNET
>            Priority: Minor
>
> Hi,
> The behavior of the method StringUtils.difference () behaves in a non-intuitive (explain in the javadoc).
> StringUtils.difference ("abc", "") returns "" as intuitively expected to be "abc".
> Is it possible to change this behavior ?
> Regards,
> Arnaud

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (LANG-784) Strange behavior on StringUtils.difference

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13184807#comment-13184807 ]

Henri Yandell commented on LANG-784:
------------------------------------

I agreed with Arnaud that this is odd. Primarily because of the following:

    System.err.println(StringUtils.difference("abc", "ab"));

This results in an empty String. That's just useless :) The answer is "c" and not empty String. Easy to fix by swapping the parameters based on length so that the longer parameter is always second.

API-wise, I wouldn't want to change if it was only the example that Arnaud lists, but if any related content returns a non-intuitive reply it seems to me that the method is buggy and should be fixed.
               

> Strange behavior on StringUtils.difference
> ------------------------------------------
>
>                 Key: LANG-784
>                 URL: https://issues.apache.org/jira/browse/LANG-784
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.0.1
>            Reporter: Arnaud BRUNET
>            Priority: Minor
>
> Hi,
> The behavior of the method StringUtils.difference () behaves in a non-intuitive (explain in the javadoc).
> StringUtils.difference ("abc", "") returns "" as intuitively expected to be "abc".
> Is it possible to change this behavior ?
> Regards,
> Arnaud

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (LANG-784) Strange behavior on StringUtils.difference

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13184871#comment-13184871 ]

Sebb commented on LANG-784:
---------------------------

Or the Javadoc should be fixed.

The first sentence is misleading as can be taken to imply that the method is symmetric.

However, the method currently behaves more like arithmetical difference, which is not symmetric.

Are there any use cases where the non-symmetric behaviour is useful?

If we are not sure, then one could add a symmetricDifference method.
               

> Strange behavior on StringUtils.difference
> ------------------------------------------
>
>                 Key: LANG-784
>                 URL: https://issues.apache.org/jira/browse/LANG-784
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.0.1
>            Reporter: Arnaud BRUNET
>            Priority: Minor
>
> Hi,
> The behavior of the method StringUtils.difference () behaves in a non-intuitive (explain in the javadoc).
> StringUtils.difference ("abc", "") returns "" as intuitively expected to be "abc".
> Is it possible to change this behavior ?
> Regards,
> Arnaud

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira