You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ecs-dev@jakarta.apache.org by "Mauro Manfrin (JIRA)" <ji...@apache.org> on 2008/06/25 18:20:45 UTC

[jira] Created: (ECS-1) addElement(Element element) methods can fail

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
            Priority: Critical


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: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


[jira] Reopened: (ECS-1) addElement(Element element) methods can fail

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

Mauro Manfrin reopened ECS-1:
-----------------------------


Perfect, thank you...I really don't want to disturb you...
but some important adjustings are missing:
Here is the list:

org.apache.ecs.rtf.Alignment.java     fails because removeElementFromRegistry uses element hascode to remove an element. The patch is:

# This patch file was generated by NetBeans IDE
Index: Alignment.java
--- Alignment.java Base (BASE)
+++ Alignment.java Locally Modified (Based On LOCAL)
@@ -131,7 +131,7 @@
     */
     public Element removeElementFromRegistry(Element element)
     {
-        type.removeElementFromRegistry(Integer.toString(element.hashCode()));
+        type.removeElementFromRegistry(element);
         return(type);
     }



 
org.apache.ecs.StringElement.java    continues to fail beacuse still uses hashcodes!  The patch is:

# This patch file was generated by NetBeans IDE
Index: StringElement.java
--- StringElement.java Base (BASE)
+++ StringElement.java Locally Modified (Based On LOCAL)
@@ -105,7 +105,7 @@
      */
     public StringElement addElement(String element)
     {
-        addElement(Integer.toString(element.hashCode()),element);
+        addElementToRegistry(element);
         return(this);
     }
     



org.apache.ecs.html.Caption.java      continues to fail beacuse still uses hashcodes!  The patch is:

# This patch file was generated by NetBeans IDE
Index: Caption.java
--- Caption.java Base (BASE)
+++ Caption.java Locally Modified (Based On LOCAL)
@@ -77,7 +77,7 @@
     */
     public Caption addElement(String element)
     {
-        addElementToRegistry(Integer.toString(element.hashCode()),element);
\ No newline at end of file
+        addElementToRegistry(element);
\ No newline at end of file
         return(this);
     }



 
org.apache.ecs.html.Select.java      now uses a deprecated (and expensive) way of iterating on elements. The patch is:

# This patch file was generated by NetBeans IDE
Index: Select.java
--- Select.java Base (BASE)
+++ Select.java Locally Modified (Based On LOCAL)
@@ -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);


org.apache.ecs.xhtml.caption.java      continues to fail beacuse still uses hashcodes!  The patch is:

# This patch file was generated by NetBeans IDE
Index: caption.java
--- caption.java Base (BASE)
+++ caption.java Locally Modified (Based On LOCAL)
@@ -91,7 +91,7 @@
     */
     public caption addElement(String element)
     {
-        addElementToRegistry(Integer.toString(element.hashCode()),element);
+        addElementToRegistry(element);
         return(this);
     }
 


Thank you in advance. 
Mauro

> 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, secondConcreteElement.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: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


[jira] Closed: (ECS-1) addElement(Element element) methods can fail

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

Robert Burrell Donkin closed ECS-1.
-----------------------------------

    Resolution: Fixed

Committed. Many Thanks.

Please test and reopen if it hasn't be applied cleanly. (The diffs didn't apply cleanly against trunk, most likely due to formatting issues.)

Apologies for my slowness and thanks again for taking the trouble to report and fix this issue.

Robert

> 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, secondConcreteElement.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: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


[jira] Commented: (ECS-1) addElement(Element element) methods can fail

Posted by "Robert Burrell Donkin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ECS-1?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12609702#action_12609702 ] 

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

Hi Mauro

I'm going to take a look at these now. 

Please bear in mind that patches containing just the differences are preferred. To create a suitable patch, use svn diff against a checkout.

Robert

> 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: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


[jira] Commented: (ECS-1) addElement(Element element) methods can fail

Posted by "Robert Burrell Donkin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ECS-1?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12609720#action_12609720 ] 

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

The problem with the approach taken in this patch is that it's no longer possible to enumerate via keys. Though this isn't a complete blocker, it would break binary compatibility and I would prefer an approach that would preserve this if possible.

Perhaps the real problem is that ECS does not check for the existance of an existing value which is not identical to the element being registered before setting the value. Perhaps another value could be used in this case. There may well be other issues with this approach, though.

I need some time to think more on this

Robert

> 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: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


[jira] Commented: (ECS-1) addElement(Element element) methods can fail

Posted by "Robert Burrell Donkin (JIRA)" <ji...@apache.org>.
    [ 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: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


[jira] Updated: (ECS-1) addElement(Element element) methods can fail

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

Mauro Manfrin updated ECS-1:
----------------------------

    Attachment: secondConcreteElement.zip

> 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, secondConcreteElement.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: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


[jira] Commented: (ECS-1) addElement(Element element) methods can fail

Posted by "Mauro Manfrin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ECS-1?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12610191#action_12610191 ] 

Mauro Manfrin commented on ECS-1:
---------------------------------

Ok, you're right! I'm wrong.

I work on these issue some months ago, and so I forgot these details.
I commented out those lines to avoid confusion, but for binary compatibility that is a problem, I know.

I have 2 solutions:
1) changing the semantics for the keys enumeration; that enumeration will enumerate only "explictly given" keys (someone really used that enumeration?) 
2) reimplementing a new keys() method (and also deprecating it) to construct an enumeration of objects in registryList, inventing a new key for all those elements without an "explicitly given name" (elements not in registry). The new name is something like #@HcAg@#454545 where 454545 is the hascode for the object.
Then, perfecting registry access methods to recognize those names, and looking excplicitly in registryList for objects with the correct hashcode.
This new implementation of keys() should guarantee binary compatibility, and deprecation of that method will prevent hascode complex accesses and hascode issues.


For the second solution, I'll attach "secondConcreteElement.zip" with the ConcreteElement.java class and ConcreteElement.patch (created with NetBeansSvn...hope it works).

That seems to work good; here you have a little test that fills a registry and then empties that registry:

public static void main(String[] ss) {
        Div d=new Div();
        d.addElementToRegistry(new BR());
        P p=new P();
        d.addElementToRegistry("myMainParagraph",p);
        d.addElementToRegistry(new Div());
        d.addElementToRegistry("string content");
        
        Enumeration e=d.keys();
        while (e.hasMoreElements()) {
            String  s=(String)e.nextElement();
            System.out.println(s);
            d.removeElement(s);
        }
        
        
        System.out.println(d);
    }



What do you think?

Mauro



> 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: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


[jira] Assigned: (ECS-1) addElement(Element element) methods can fail

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

Robert Burrell Donkin reassigned ECS-1:
---------------------------------------

    Assignee: Robert Burrell Donkin

> 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: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


[jira] Commented: (ECS-1) addElement(Element element) methods can fail

Posted by "Mauro Manfrin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ECS-1?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12609824#action_12609824 ] 

Mauro Manfrin commented on ECS-1:
---------------------------------

I tried an approach like that described by you (checking for existence), before. 
The issue is efficiency. That way is slower because it  has to check for existence every 'add' operation. Then, if the objects already exists, it has to generate e second key (how?). 
So I tried another approach: generating a key on every add operation, using a counter. That is possible, but my final solution is much more efficient: it doesn't make use of counters and it construct Hashtables only if really useful (in a normal construction of a page you'll rarely want to give a key to a tag).
So my approach is quicker and uses less memory (useful on crowded web servers).


I can't understand when you say that "it's no longer possible to enumerate via keys". 
ConcreteElement doesn't have methods to Enumerate via keys! (an why enumerating via a key beeing the hasCode of elements?) 
The only enumerate method in ConcreteElement (elements()) is on the full list on all childs! And that works good.

So I can't see binary compatibility issues. I'll try to convince you.

The only break in binary compatibility could be that:
if you add an Element to the registry using a key, it is expected that you access that element via the key or the element itself, but if you add the element without giving it a key, it is expected that you access that element via the element itself (not via his hascode).

In substance, only code like:

concrete.addElementToRegistry(element);
concrete.removeElementFromRegistry(element.hashCode())

no longer works...but I think that this is a bad code. 
It is based on the never stated assumption that ConcreteElement implementation is based on hascodes!!!

Let me know...

Mauro

> 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: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


[jira] Commented: (ECS-1) addElement(Element element) methods can fail

Posted by "Robert Burrell Donkin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ECS-1?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12614535#action_12614535 ] 

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

Hi Mauro

Sounds good :-)

ECS was created before the unit testing revolution (if you can remember those days) so I'm going to need a clear head to analyse the patch. Hopefully, should get to before the end of the weekend.

Thanks for your patience.

Robert

> 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, secondConcreteElement.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: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


[jira] Updated: (ECS-1) addElement(Element element) methods can fail

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

Mauro Manfrin updated ECS-1:
----------------------------

    Attachment: ecs-maintrunk-patches.zip

This is a version of ConcreteElement that sotores object in the Map only if you give explicitly a key-name, otherwise it stores only in the Vector. 
That seems to work good, with a good retro-compatibility.

I modified classes since the jakarta ECS SVN repository.
You will find the ConcreteElement class, and subsequent 5 classes adaptions.
Pay attention, these patches are based on the trunk, not the 1.4.2 version.


> 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
>            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: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org