You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Mikhail Fursov (JIRA)" <ji...@apache.org> on 2006/05/19 14:03:29 UTC

[jira] Created: (HARMONY-482) Some code compares Strings with == operator

Some code compares Strings with == operator
-------------------------------------------

         Key: HARMONY-482
         URL: http://issues.apache.org/jira/browse/HARMONY-482
     Project: Harmony
        Type: Bug

  Components: Classlib  
    Reporter: Mikhail Fursov
    Priority: Trivial


Some classes  (e.g. org.apache.harmony.luni.internal.net.www.protocol.http.HttpUrlConnection) use string comparison by reference instead of comparison by value.
Such optimization is legal but can lead to problems with compatibility and bugs when part of the code refactored.


        if (method == "GET")
            setRequestMethod("POST");
        // If the request method is neither PUT or POST, then you're not writing
        if (method != "PUT" && method != "POST")
            throw new ProtocolException(Msg.getString("K008f", method));



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Re: [jira] Commented: (HARMONY-482) Some code compares Strings with == operator

Posted by Mikhail Loenko <ml...@gmail.com>.
it works! :)

2006/5/23, Mikhail Fursov <mi...@gmail.com>:
> String post1=new String("POST");
> String post2=new String("POST");
>
> :)
>
>
> On 5/23/06, Mikhail Loenko <ml...@gmail.com> wrote:
> >
> > This is the only way I've found to make
> > two different object instances of "POST" string, such that:
> >
> > post1.equals("POST");
> > AND
> > post2.equals("POST");
> > AND
> > post1!=post2
> >
> > Feel free to suggest another way
> >
> > Thanks,
> > Mikhail
> >
> > 2
>
>
>
>
> --
> Mikhail Fursov
> Intel Middleware Products Division
>
>

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [jira] Commented: (HARMONY-482) Some code compares Strings with == operator

Posted by Mikhail Fursov <mi...@gmail.com>.
String post1=new String("POST");
String post2=new String("POST");

:)


On 5/23/06, Mikhail Loenko <ml...@gmail.com> wrote:
>
> This is the only way I've found to make
> two different object instances of "POST" string, such that:
>
> post1.equals("POST");
> AND
> post2.equals("POST");
> AND
> post1!=post2
>
> Feel free to suggest another way
>
> Thanks,
> Mikhail
>
> 2




-- 
Mikhail Fursov
Intel Middleware Products Division

Re: [jira] Commented: (HARMONY-482) Some code compares Strings with == operator

Posted by Mikhail Loenko <ml...@gmail.com>.
This is the only way I've found to make
two different object instances of "POST" string, such that:

post1.equals("POST");
AND
post2.equals("POST");
AND
post1!=post2

Feel free to suggest another way

Thanks,
Mikhail

2006/5/23, Andrew Zhang <zh...@gmail.com>:
> Hi, Mikhail,
>
> I found some code looks strange in the patch, such as
>  c.method = pos + t;
>  c.method = ge+ t;
>
> Is there any reason to write in such way?
>
> Thanks!
>
>
> On 5/22/06, Mikhail Loenko (JIRA) <ji...@apache.org> wrote:
> >
> >    [
> > http://issues.apache.org/jira/browse/HARMONY-482?page=comments#action_12412723]
> >
> > Mikhail Loenko commented on HARMONY-482:
> > ----------------------------------------
> >
> > If the code remains unmodified, this works fine.
> > I think the best way is to develop a unit test that would prevent
> > undesired modifications in the code
> >
> > > Some code compares Strings with == operator
> > > -------------------------------------------
> > >
> > >          Key: HARMONY-482
> > >          URL: http://issues.apache.org/jira/browse/HARMONY-482
> > >      Project: Harmony
> > >         Type: Bug
> >
> > >   Components: Classlib
> > >     Reporter: Mikhail Fursov
> > >     Assignee: Mikhail Loenko
> > >     Priority: Trivial
> >
> > >
> > > Some classes  (e.g.
> > org.apache.harmony.luni.internal.net.www.protocol.http.HttpUrlConnection)
> > use string comparison by reference instead of comparison by value.
> > > Such optimization is legal but can lead to problems with compatibility
> > and bugs when part of the code refactored.
> > >         if (method == "GET")
> > >             setRequestMethod("POST");
> > >         // If the request method is neither PUT or POST, then you're not
> > writing
> > >         if (method != "PUT" && method != "POST")
> > >             throw new ProtocolException(Msg.getString("K008f", method));
> >
> > --
> > This message is automatically generated by JIRA.
> > -
> > If you think it was sent incorrectly contact one of the administrators:
> >   http://issues.apache.org/jira/secure/Administrators.jspa
> > -
> > For more information on JIRA, see:
> >   http://www.atlassian.com/software/jira
> >
> >
>
>
> --
> Andrew Zhang
> China Software Development Lab, IBM
>
>

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [jira] Commented: (HARMONY-482) Some code compares Strings with == operator

Posted by Andrew Zhang <zh...@gmail.com>.
Hi, Mikhail,

I found some code looks strange in the patch, such as
 c.method = pos + t;
 c.method = ge+ t;

Is there any reason to write in such way?

Thanks!


On 5/22/06, Mikhail Loenko (JIRA) <ji...@apache.org> wrote:
>
>    [
> http://issues.apache.org/jira/browse/HARMONY-482?page=comments#action_12412723]
>
> Mikhail Loenko commented on HARMONY-482:
> ----------------------------------------
>
> If the code remains unmodified, this works fine.
> I think the best way is to develop a unit test that would prevent
> undesired modifications in the code
>
> > Some code compares Strings with == operator
> > -------------------------------------------
> >
> >          Key: HARMONY-482
> >          URL: http://issues.apache.org/jira/browse/HARMONY-482
> >      Project: Harmony
> >         Type: Bug
>
> >   Components: Classlib
> >     Reporter: Mikhail Fursov
> >     Assignee: Mikhail Loenko
> >     Priority: Trivial
>
> >
> > Some classes  (e.g.
> org.apache.harmony.luni.internal.net.www.protocol.http.HttpUrlConnection)
> use string comparison by reference instead of comparison by value.
> > Such optimization is legal but can lead to problems with compatibility
> and bugs when part of the code refactored.
> >         if (method == "GET")
> >             setRequestMethod("POST");
> >         // If the request method is neither PUT or POST, then you're not
> writing
> >         if (method != "PUT" && method != "POST")
> >             throw new ProtocolException(Msg.getString("K008f", method));
>
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the administrators:
>   http://issues.apache.org/jira/secure/Administrators.jspa
> -
> For more information on JIRA, see:
>   http://www.atlassian.com/software/jira
>
>


-- 
Andrew Zhang
China Software Development Lab, IBM

[jira] Resolved: (HARMONY-482) Some code compares Strings with == operator

Posted by "Mikhail Loenko (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-482?page=all ]
     
Mikhail Loenko resolved HARMONY-482:
------------------------------------

    Resolution: Fixed

fixed in revision 408876
Mikhail, please check that it fully resolves the problem

> Some code compares Strings with == operator
> -------------------------------------------
>
>          Key: HARMONY-482
>          URL: http://issues.apache.org/jira/browse/HARMONY-482
>      Project: Harmony
>         Type: Bug

>   Components: Classlib
>     Reporter: Mikhail Fursov
>     Assignee: Mikhail Loenko
>     Priority: Trivial
>  Attachments: patch.txt
>
> Some classes  (e.g. org.apache.harmony.luni.internal.net.www.protocol.http.HttpUrlConnection) use string comparison by reference instead of comparison by value.
> Such optimization is legal but can lead to problems with compatibility and bugs when part of the code refactored.
>         if (method == "GET")
>             setRequestMethod("POST");
>         // If the request method is neither PUT or POST, then you're not writing
>         if (method != "PUT" && method != "POST")
>             throw new ProtocolException(Msg.getString("K008f", method));

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (HARMONY-482) Some code compares Strings with == operator

Posted by "Mikhail Loenko (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-482?page=all ]
     
Mikhail Loenko closed HARMONY-482:
----------------------------------


verified by Mikhail Fursov

> Some code compares Strings with == operator
> -------------------------------------------
>
>          Key: HARMONY-482
>          URL: http://issues.apache.org/jira/browse/HARMONY-482
>      Project: Harmony
>         Type: Bug

>   Components: Classlib
>     Reporter: Mikhail Fursov
>     Assignee: Mikhail Loenko
>     Priority: Trivial
>  Attachments: patch.txt
>
> Some classes  (e.g. org.apache.harmony.luni.internal.net.www.protocol.http.HttpUrlConnection) use string comparison by reference instead of comparison by value.
> Such optimization is legal but can lead to problems with compatibility and bugs when part of the code refactored.
>         if (method == "GET")
>             setRequestMethod("POST");
>         // If the request method is neither PUT or POST, then you're not writing
>         if (method != "PUT" && method != "POST")
>             throw new ProtocolException(Msg.getString("K008f", method));

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (HARMONY-482) Some code compares Strings with == operator

Posted by "Mikhail Fursov (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-482?page=comments#action_12413103 ] 

Mikhail Fursov commented on HARMONY-482:
----------------------------------------

Thank you, now problem is fixed.

> Some code compares Strings with == operator
> -------------------------------------------
>
>          Key: HARMONY-482
>          URL: http://issues.apache.org/jira/browse/HARMONY-482
>      Project: Harmony
>         Type: Bug

>   Components: Classlib
>     Reporter: Mikhail Fursov
>     Assignee: Mikhail Loenko
>     Priority: Trivial
>  Attachments: patch.txt
>
> Some classes  (e.g. org.apache.harmony.luni.internal.net.www.protocol.http.HttpUrlConnection) use string comparison by reference instead of comparison by value.
> Such optimization is legal but can lead to problems with compatibility and bugs when part of the code refactored.
>         if (method == "GET")
>             setRequestMethod("POST");
>         // If the request method is neither PUT or POST, then you're not writing
>         if (method != "PUT" && method != "POST")
>             throw new ProtocolException(Msg.getString("K008f", method));

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (HARMONY-482) Some code compares Strings with == operator

Posted by "Mikhail Loenko (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-482?page=comments#action_12412723 ] 

Mikhail Loenko commented on HARMONY-482:
----------------------------------------

If the code remains unmodified, this works fine.
I think the best way is to develop a unit test that would prevent undesired modifications in the code

> Some code compares Strings with == operator
> -------------------------------------------
>
>          Key: HARMONY-482
>          URL: http://issues.apache.org/jira/browse/HARMONY-482
>      Project: Harmony
>         Type: Bug

>   Components: Classlib
>     Reporter: Mikhail Fursov
>     Assignee: Mikhail Loenko
>     Priority: Trivial

>
> Some classes  (e.g. org.apache.harmony.luni.internal.net.www.protocol.http.HttpUrlConnection) use string comparison by reference instead of comparison by value.
> Such optimization is legal but can lead to problems with compatibility and bugs when part of the code refactored.
>         if (method == "GET")
>             setRequestMethod("POST");
>         // If the request method is neither PUT or POST, then you're not writing
>         if (method != "PUT" && method != "POST")
>             throw new ProtocolException(Msg.getString("K008f", method));

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (HARMONY-482) Some code compares Strings with == operator

Posted by "Mikhail Loenko (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-482?page=comments#action_12412724 ] 

Mikhail Loenko commented on HARMONY-482:
----------------------------------------

Seems like it works due to J9 features, might be worse with other VMs

> Some code compares Strings with == operator
> -------------------------------------------
>
>          Key: HARMONY-482
>          URL: http://issues.apache.org/jira/browse/HARMONY-482
>      Project: Harmony
>         Type: Bug

>   Components: Classlib
>     Reporter: Mikhail Fursov
>     Assignee: Mikhail Loenko
>     Priority: Trivial

>
> Some classes  (e.g. org.apache.harmony.luni.internal.net.www.protocol.http.HttpUrlConnection) use string comparison by reference instead of comparison by value.
> Such optimization is legal but can lead to problems with compatibility and bugs when part of the code refactored.
>         if (method == "GET")
>             setRequestMethod("POST");
>         // If the request method is neither PUT or POST, then you're not writing
>         if (method != "PUT" && method != "POST")
>             throw new ProtocolException(Msg.getString("K008f", method));

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (HARMONY-482) Some code compares Strings with == operator

Posted by "Mikhail Loenko (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-482?page=all ]

Mikhail Loenko updated HARMONY-482:
-----------------------------------

    Attachment: patch.txt

please review my unit test and patch

> Some code compares Strings with == operator
> -------------------------------------------
>
>          Key: HARMONY-482
>          URL: http://issues.apache.org/jira/browse/HARMONY-482
>      Project: Harmony
>         Type: Bug

>   Components: Classlib
>     Reporter: Mikhail Fursov
>     Assignee: Mikhail Loenko
>     Priority: Trivial
>  Attachments: patch.txt
>
> Some classes  (e.g. org.apache.harmony.luni.internal.net.www.protocol.http.HttpUrlConnection) use string comparison by reference instead of comparison by value.
> Such optimization is legal but can lead to problems with compatibility and bugs when part of the code refactored.
>         if (method == "GET")
>             setRequestMethod("POST");
>         // If the request method is neither PUT or POST, then you're not writing
>         if (method != "PUT" && method != "POST")
>             throw new ProtocolException(Msg.getString("K008f", method));

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (HARMONY-482) Some code compares Strings with == operator

Posted by "Mikhail Fursov (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-482?page=comments#action_12412903 ] 

Mikhail Fursov commented on HARMONY-482:
----------------------------------------

Mikhail,
I checked the patch and found no errors in it.

BTW may be we should come to an agreement do not use in Harmony "magic numbers" or "magic strings" in code at all and deal with constants only?

> Some code compares Strings with == operator
> -------------------------------------------
>
>          Key: HARMONY-482
>          URL: http://issues.apache.org/jira/browse/HARMONY-482
>      Project: Harmony
>         Type: Bug

>   Components: Classlib
>     Reporter: Mikhail Fursov
>     Assignee: Mikhail Loenko
>     Priority: Trivial
>  Attachments: patch.txt
>
> Some classes  (e.g. org.apache.harmony.luni.internal.net.www.protocol.http.HttpUrlConnection) use string comparison by reference instead of comparison by value.
> Such optimization is legal but can lead to problems with compatibility and bugs when part of the code refactored.
>         if (method == "GET")
>             setRequestMethod("POST");
>         // If the request method is neither PUT or POST, then you're not writing
>         if (method != "PUT" && method != "POST")
>             throw new ProtocolException(Msg.getString("K008f", method));

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Assigned: (HARMONY-482) Some code compares Strings with == operator

Posted by "Mikhail Loenko (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-482?page=all ]

Mikhail Loenko reassigned HARMONY-482:
--------------------------------------

    Assign To: Mikhail Loenko

> Some code compares Strings with == operator
> -------------------------------------------
>
>          Key: HARMONY-482
>          URL: http://issues.apache.org/jira/browse/HARMONY-482
>      Project: Harmony
>         Type: Bug

>   Components: Classlib
>     Reporter: Mikhail Fursov
>     Assignee: Mikhail Loenko
>     Priority: Trivial

>
> Some classes  (e.g. org.apache.harmony.luni.internal.net.www.protocol.http.HttpUrlConnection) use string comparison by reference instead of comparison by value.
> Such optimization is legal but can lead to problems with compatibility and bugs when part of the code refactored.
>         if (method == "GET")
>             setRequestMethod("POST");
>         // If the request method is neither PUT or POST, then you're not writing
>         if (method != "PUT" && method != "POST")
>             throw new ProtocolException(Msg.getString("K008f", method));

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira