[ 
https://issues.apache.org/jira/browse/ECS-1?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12610040#action_12610040
 ] 

Robert Burrell Donkin commented on ECS-1:
-----------------------------------------

It's harder for me to work from sample files than a clean patch. Below is the 
patch that I'm using (it's a svn diff). It's possible that I haven't been able 
to convert accurately. 

+//     public Enumeration keys()
+//     {
+//             return(registryList.elements());
+//     }

is commented out in the patched version and so the patched code looks like it's 
no longer binary compatible with the last release. 

Robert 

Index: src/java/org/apache/ecs/rtf/Alignment.java
===================================================================
--- src/java/org/apache/ecs/rtf/Alignment.java  (revision 673206)
+++ src/java/org/apache/ecs/rtf/Alignment.java  (working copy)
@@ -131,7 +131,7 @@
     */
     public Element removeElementFromRegistry(Element element)
     {
-        type.removeElementFromRegistry(Integer.toString(element.hashCode()));
+        type.removeElementFromRegistry(element);
         return(type);
     }
 
Index: src/java/org/apache/ecs/ConcreteElement.java
===================================================================
--- src/java/org/apache/ecs/ConcreteElement.java        (revision 673206)
+++ src/java/org/apache/ecs/ConcreteElement.java        (working copy)
@@ -42,7 +42,7 @@
        private static String lineSeparator = 
System.getProperty("line.separator");
 
     /** @serial registry registry */
-    private Hashtable registry = new Hashtable(4); // keep a list of elements 
that need to be added to the element
+    private Hashtable registry; // keep a list of elements that need to be 
added to the element
     /** Maintain an ordered list of elements */
     private Vector registryList = new Vector(2);
 
@@ -54,13 +54,10 @@
         If the object is in the registry return otherwise return null.
         @param element the name of the object to locate.
     */
-    public ConcreteElement getElement(String element)
+    public ConcreteElement getElement(String name)
     {
-        if(registry.containsKey(element))
-        {
-            return (ConcreteElement)registry.get(element);
-        }
-        return null;
+        if (registry==null) return null;
+        return (ConcreteElement)registry.get(name);
     }
 
     /**
@@ -71,7 +68,7 @@
     {
         if ( element == null )
             return(this);
-        addElementToRegistry(Integer.toString(element.hashCode()),element);
+        addElementToRegistry(null,element);
         return(this);
     }
 
@@ -80,17 +77,20 @@
         @param   hashcode internal name of element
         @param   element element to be added to the registry.
     */
-    public Element addElementToRegistry(String hashcode,Element element)
+    public Element addElementToRegistry(String name,Element element)
     {
-        if ( hashcode == null || element == null )
+        if ( element == null )
             return(this);
 
          element.setFilterState(getFilterState());
          if(ECSDefaults.getDefaultPrettyPrint() != element.getPrettyPrint())
               element.setPrettyPrint(getPrettyPrint());
-         registry.put(hashcode,element);
-         if(!registryList.contains(hashcode))
-            registryList.addElement(hashcode);
+         if (name!=null) {
+             if (registry==null) registry=new Hashtable(4);
+             registry.put(name,element);
+         }
+         if(!registryList.contains(element))
+            registryList.addElement(element);
          return(this);
     }
 
@@ -105,7 +105,7 @@
         if ( element == null )
             return(this);
         setFilterState(filter);
-        addElementToRegistry(Integer.toString(element.hashCode()),element);
+        addElementToRegistry(null,element);
         return(this);
     }
 
@@ -114,12 +114,12 @@
         @param   element element to be added to the registry.
         @param   filter  should we filter this element?
     */
-    public Element addElementToRegistry(String hashcode, Element 
element,boolean filter)
+    public Element addElementToRegistry(String name, Element element,boolean 
filter)
     {
-        if ( hashcode == null )
+        if ( name == null )
             return(this);
         setFilterState(filter);
-        addElementToRegistry(hashcode,element);
+        addElementToRegistry(name,element);
         return(this);
     }
 
@@ -133,7 +133,7 @@
         if ( value == null )
             return(this);
         setFilterState(filter);
-        addElementToRegistry(Integer.toString(value.hashCode()),value);
+        addElementToRegistry(value);
         return(this);
     }
 
@@ -143,12 +143,12 @@
         @param   element element to be added to the registry.
         @param   filter does this need to be filtered?
     */
-    public Element addElementToRegistry(String hashcode, String value,boolean 
filter)
+    public Element addElementToRegistry(String name, String value,boolean 
filter)
     {
-        if ( hashcode == null )
+        if ( name == null )
             return(this);
         setFilterState(filter);
-        addElementToRegistry(hashcode,value);
+        addElementToRegistry(name,value);
         return(this);
     }
 
@@ -168,9 +168,9 @@
         Registers an element in the head element list
         @param   element element to be added to the registry.
     */
-    public Element addElementToRegistry(String hashcode,String value)
+    public Element addElementToRegistry(String name,String value)
     {
-        if ( hashcode == null )
+        if ( name == null )
             return(this);
 
         // We do it this way so that filtering will work.
@@ -183,7 +183,7 @@
         se.setFilterState(getFilterState());
         se.setFilter(getFilter());
         se.setPrettyPrint(getPrettyPrint());
-        addElementToRegistry(hashcode,se);
+        addElementToRegistry(name,se);
         return(this);
     }
 
@@ -193,7 +193,7 @@
     */
     public Element removeElementFromRegistry(Element element)
     {
-        removeElementFromRegistry(Integer.toString(element.hashCode()));
+        registryList.remove(element);
         return(this);
     }
 
@@ -201,10 +201,11 @@
         Removes an element from the head element registry
         @param   hashcode element to be added to the registry.
     */
-    public Element removeElementFromRegistry(String hashcode)
+    public Element removeElementFromRegistry(String name)
     {
-        registry.remove(hashcode);
-        registryList.removeElement(hashcode);
+        if (registry==null) return this;
+        Object o=registry.remove(name);
+        if (o!=null) registryList.removeElement(o);
         return(this);
     }
 
@@ -214,32 +215,33 @@
     */
     public boolean registryHasElement(Element element)
     {
-        return(registry.contains(element));
+        return(registryList.contains(element));
     }
 
        /**
                Get the keys of this element.
        */
-       public Enumeration keys()
-       {
-               return(registryList.elements());
-       }
+//     public Enumeration keys()
+//     {
+//             return(registryList.elements());
+//     }
 
     /**
         Get an enumeration of the elements that this element contains.
     */
     public Enumeration elements()
     {
-        return(registry.elements());
+        return(registryList.elements());
     }
 
     /**
         Find out if this element is in the element registry.
         @param element find out if this element is in the registry
     */
-    public boolean registryHasElement(String hashcode)
+    public boolean registryHasElement(String name)
     {
-        return(registry.containsKey(hashcode));
+        if (registry==null) return false;
+        return(registry.containsKey(name));
     }
 
     /**
@@ -262,7 +264,7 @@
         int tabLevel = ce.getTabLevel();
         try
         {
-            if (ce.registry.size() == 0)
+            if (ce.registryList.size() == 0)
             {  
                 ce.output(out);
             }
@@ -281,7 +283,7 @@
 
                 while(enum_.hasMoreElements())
                 {
-                    Object obj = ce.registry.get((String)enum_.nextElement());
+                    Object obj = (Object)enum_.nextElement();
                     if(obj instanceof GenericElement)
                     {
                         Element e = (Element)obj;
@@ -336,7 +338,7 @@
     */
     public void output(OutputStream out)
        {
-               if (this.registry.size() == 0)
+               if (this.registryList.size() == 0)
                {
                                int tabLevel = getTabLevel();
                                if ((getPrettyPrint() && this instanceof 
Printable) && (tabLevel > 0))  
@@ -376,7 +378,7 @@
        {
                boolean prettyPrint = getPrettyPrint();
                int tabLevel = getTabLevel();
-               if (registry.size() == 0)
+               if (registryList.size() == 0)
                {
                        if ((prettyPrint && this instanceof Printable) && 
(tabLevel > 0))
                                putTabs(tabLevel, out);
@@ -396,7 +398,7 @@
             Enumeration enum_ = registryList.elements();
                        while(enum_.hasMoreElements())
                        {
-                               Object obj = 
registry.get((String)enum_.nextElement());
+                               Object obj = (Object)enum_.nextElement();
                                if(obj instanceof GenericElement)
                                {
                                        Element e = (Element)obj;
Index: src/java/org/apache/ecs/xhtml/caption.java
===================================================================
--- src/java/org/apache/ecs/xhtml/caption.java  (revision 673206)
+++ src/java/org/apache/ecs/xhtml/caption.java  (working copy)
@@ -91,7 +91,7 @@
     */
     public caption addElement(String element)
     {
-        addElementToRegistry(Integer.toString(element.hashCode()),element);
+        addElementToRegistry(element);
         return(this);
     }
 
Index: src/java/org/apache/ecs/StringElement.java
===================================================================
--- src/java/org/apache/ecs/StringElement.java  (revision 673206)
+++ src/java/org/apache/ecs/StringElement.java  (working copy)
@@ -105,7 +105,7 @@
      */
     public StringElement addElement(String element)
     {
-        addElement(Integer.toString(element.hashCode()),element);
+        addElementToRegistry(element);
         return(this);
     }
     
Index: src/java/org/apache/ecs/html/Caption.java
===================================================================
--- src/java/org/apache/ecs/html/Caption.java   (revision 673206)
+++ src/java/org/apache/ecs/html/Caption.java   (working copy)
@@ -77,7 +77,7 @@
     */
     public Caption addElement(String element)
     {
-        addElementToRegistry(Integer.toString(element.hashCode()),element);
+        addElementToRegistry(element);
         return(this);
     }
 
Index: src/java/org/apache/ecs/html/Select.java
===================================================================
--- src/java/org/apache/ecs/html/Select.java    (revision 673206)
+++ src/java/org/apache/ecs/html/Select.java    (working copy)
@@ -177,10 +177,10 @@
 
     public Select selectOption(int option)
     {
-        Enumeration enum_ = keys();
+        Enumeration enum_ = elements();
         for(int x = 0; enum_.hasMoreElements(); x++)
         {
-            ConcreteElement element = 
(ConcreteElement)getElement((String)enum_.nextElement());
+            ConcreteElement element = (ConcreteElement)enum_.nextElement();
             if(x == option)
             {
                 ((Option)element).setSelected(true);


> addElement(Element element) methods can fail
> --------------------------------------------
>
>                 Key: ECS-1
>                 URL: https://issues.apache.org/jira/browse/ECS-1
>             Project: ECS
>          Issue Type: Bug
>         Environment: in Ibm Virtual Machines, but probabily also in Sun 
> Virtual Machines
>            Reporter: Mauro Manfrin
>            Assignee: Robert Burrell Donkin
>            Priority: Critical
>         Attachments: ecs-maintrunk-patches.zip
>
>
> The class ConcreteElement exposes a method
> addElement(Element element)
> that calls
> addElementToRegistry(Integer.toString(element.hashCode()),element);
> so it gives a key valued element.hashCode() to that element.
> That's the point: element.hashCode() can't be a unique key because sometimes 
> we can have two elements with the same hasocode.
> javadoc states:
> "It is not required that if two objects are unequal according to the 
> equals(java.lang.Object) method, then calling the hashCode method on each of 
> the two objects must produce distinct integer results. However, the 
> programmer should be aware that producing distinct integer results for 
> unequal objects may improve the performance of hashtables."
> So sometimes, two different objects can have the same hashCode!
> So, sometimes two calls to addElement(element) can result in only the second 
> object stored in the ConcreteElement.
> So sometimes, on out instalaltion some table rows misses, or some row cells 
> misses or...

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to