As far as I can see from the GWT code, this is actually to do with the String 
performance 
improvements in HashMap after 1.5. Because your map has String keys, GWT treats 
them specially and 
makes use of JavaScripts native binding of strings to values in objects:

private native V getStringValue(String key) /*-{
     return [email protected]::stringMap[':' + key];
   }-*/;

Thus it doesn't follow the contract of HashMap when you have String keys, but 
then when it did 
everyone complained it was slow.

Paul Robinson wrote:
> I would say that is a bug in GWT. The HashMap.get() contract specifies
> in which order it will call equals() on the keys in order to check
> equality. So it shouldn't matter that there's an asymmetry in your code
> (ie that String.equals(OtherStringClass) will always return false
> because they're different classes, whereas
> OtherStringClass.equals(String) may return true)
> 
> Paul
> 
> Francisco wrote:
>> I am experiencing different behavior from host mode and web mode
>> regarding HashMap. I built a simple code which reproduces this error.
>> You can see that HashBug.getHTML() output is not the same in host and
>> web modes.
>> I've tested with gwt-windows-1.5.3, FireFox and IE.
>>
>> Is it a bug?
>>
>> Regards, Francisco.
>>
>>
>>
>> package project.client;
>>
>> import java.util.HashMap;
>>
>> import com.google.gwt.user.client.ui.HTML;
>>
>> public class HashBug {
>>      private HTML html;
>>
>>      private class OtherStringClass{
>>              String value;
>>              public OtherStringClass(String value){
>>                      this.value = value;
>>              }
>>              public String getValue(){
>>                      return this.value;
>>              }
>>              @Override
>>              public boolean equals(Object obj) {
>>                      return value.equals(obj);
>>              }
>>              @Override
>>              public int hashCode() {
>>                      return this.value.hashCode();
>>              }
>>      }
>>      public HashBug(){
>>              HashMap<String, Integer> map = new HashMap<String, Integer>();
>>              String testString = "test";
>>              OtherStringClass otherTestString = new 
>> OtherStringClass(testString);
>>              map.put(testString, new Integer(1));
>>
>>              String text = "";
>>
>>              Integer fromString = map.get(testString);
>>              if(fromString != null) text += "From string = " + 
>> fromString.intValue
>> () + " ";
>>              Integer fromOhter = map.get(otherTestString);
>>              if(fromOhter != null) text += "From other = " + 
>> fromOhter.intValue
>> ();
>>
>>              html = new HTML(text);
>>      }
>>
>>      public HTML getHTML(){
>>              return this.html;
>>      }
>> }
>>
>>   
> 
> > 
> 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to