mx4j/src/core/javax/management MBeanAttributeInfo.java,1.12,1.13 MBeanConstructorInfo.java,1.11,1.12 MBeanFeatureInfo.java,1.7,1.8 MBeanInfo.java,1.13,1.14 MBeanNotificationInfo.java,1.11,1.12 MBeanOperationInfo.java,1.11,1.12 MBeanParameterInfo.java,1.9,1.10

Simone Bordet <[email protected]> Tue, 05 Oct 2004 09:46:23 +0000
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/core/javax/management
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7692/src/core/javax/management

Modified Files:
	MBeanAttributeInfo.java MBeanConstructorInfo.java 
	MBeanFeatureInfo.java MBeanInfo.java 
	MBeanNotificationInfo.java MBeanOperationInfo.java 
	MBeanParameterInfo.java 
Log Message:
Fix for bug #1033138: hashCode() and equals() were not spec-compliant.
Also taken the chance to clean up openmbean code.

Index: MBeanConstructorInfo.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/MBeanConstructorInfo.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** MBeanConstructorInfo.java	7 Sep 2004 12:44:16 -0000	1.11
--- MBeanConstructorInfo.java	5 Oct 2004 09:46:20 -0000	1.12
***************
*** 83,87 ****
     public int hashCode()
     {
!       return super.hashCode() ^ Utils.arrayHashCode(getSignature());
     }
  
--- 83,87 ----
     public int hashCode()
     {
!       return super.hashCode() + 29 * Utils.arrayHashCode(getSignature());
     }
  
***************
*** 89,102 ****
     {
        if (!super.equals(obj)) return false;
  
!       try
!       {
!          MBeanConstructorInfo other = (MBeanConstructorInfo)obj;
!          return Utils.arrayEquals(getSignature(), other.getSignature());
!       }
!       catch (ClassCastException ignored)
!       {
!       }
!       return false;
     }
  }
--- 89,96 ----
     {
        if (!super.equals(obj)) return false;
+       if (!(obj instanceof MBeanConstructorInfo)) return false;
  
!       MBeanConstructorInfo other = (MBeanConstructorInfo)obj;
!       return Utils.arrayEquals(getSignature(), other.getSignature());
     }
  }

Index: MBeanInfo.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/MBeanInfo.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** MBeanInfo.java	4 Sep 2004 15:44:06 -0000	1.13
--- MBeanInfo.java	5 Oct 2004 09:46:20 -0000	1.14
***************
*** 106,115 ****
     public int hashCode()
     {
!       int hash = className == null ? 0 : className.hashCode();
!       if (description != null) hash ^= description.hashCode();
!       if (constructors != null) hash ^= Utils.arrayHashCode(constructors);
!       if (attributes != null) hash ^= Utils.arrayHashCode(attributes);
!       if (operations != null) hash ^= Utils.arrayHashCode(operations);
!       if (notifications != null) hash ^= Utils.arrayHashCode(notifications);
        return hash;
     }
--- 106,122 ----
     public int hashCode()
     {
!       int hash = 0;
!       String cn = getClassName();
!       if (cn != null) hash = 29 * hash + cn.hashCode();
!       String de = getDescription();
!       if (de != null) hash = 29 * hash + de.hashCode();
!       MBeanConstructorInfo[] co = getConstructors();
!       if (co != null) hash = 29 * hash + Utils.arrayHashCode(co);
!       MBeanAttributeInfo[] at = getAttributes();
!       if (at != null) hash = 29 * hash + Utils.arrayHashCode(at);
!       MBeanOperationInfo[] op = getOperations();
!       if (op != null) hash = 29 * hash + Utils.arrayHashCode(op);
!       MBeanNotificationInfo[] no = getNotifications();
!       if (no != null) hash = 29 * hash + Utils.arrayHashCode(no);
        return hash;
     }
***************
*** 117,141 ****
     public boolean equals(Object obj)
     {
-       if (obj == null) return false;
        if (obj == this) return true;
  
!       try
!       {
!          MBeanInfo other = (MBeanInfo)obj;
!          if ((className == null && other.className == null) || (className != null && className.equals(other.className)))
!          {
!             // Description ignored for equality
! 
!             if (!Utils.arrayEquals(constructors, other.constructors)) return false;
!             if (!Utils.arrayEquals(attributes, other.attributes)) return false;
!             if (!Utils.arrayEquals(operations, other.operations)) return false;
!             if (!Utils.arrayEquals(notifications, other.notifications)) return false;
!             return true;
!          }
!       }
!       catch (ClassCastException ignored)
!       {
!       }
!       return false;
     }
  }
--- 124,142 ----
     public boolean equals(Object obj)
     {
        if (obj == this) return true;
+       if (!(obj instanceof MBeanInfo)) return false;
  
!       MBeanInfo other = (MBeanInfo)obj;
!       String thisClassName = getClassName();
!       String otherClassName = other.getClassName();
!       if (thisClassName != null ? !thisClassName.equals(otherClassName) : otherClassName != null) return false;
!       String thisDescription = getDescription();
!       String otherDescription = other.getDescription();
!       if (thisDescription != null ? !thisDescription.equals(otherDescription) : otherDescription != null) return false;
!       if (!Utils.arrayEquals(getConstructors(), other.getConstructors())) return false;
!       if (!Utils.arrayEquals(getAttributes(), other.getAttributes())) return false;
!       if (!Utils.arrayEquals(getOperations(), other.getOperations())) return false;
!       if (!Utils.arrayEquals(getNotifications(), other.getNotifications())) return false;
!       return true;
     }
  }

Index: MBeanFeatureInfo.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/MBeanFeatureInfo.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** MBeanFeatureInfo.java	4 Sep 2004 15:44:06 -0000	1.7
--- MBeanFeatureInfo.java	5 Oct 2004 09:46:20 -0000	1.8
***************
*** 60,85 ****
     public int hashCode()
     {
!       String name = getName();
!       return name == null ? 0 : name.hashCode();
     }
  
     public boolean equals(Object obj)
     {
!       if (obj == null) return false;
!       if (obj == this) return true;
  
!       try
!       {
!          MBeanFeatureInfo other = (MBeanFeatureInfo)obj;
!          String name = getName();
!          String otherName = other.getName();
!          if (name != null && !name.equals(otherName)) return false;
!          if (name == null && otherName != null) return false;
!          return true;
!       }
!       catch (ClassCastException ignored)
!       {
!       }
!       return false;
     }
  }
--- 60,84 ----
     public int hashCode()
     {
!       int hash = 0;
!       String n = getName();
!       if (n != null) hash = 29 * hash + n.hashCode();
!       String d = getDescription();
!       if (d != null) hash = 29 * hash + d.hashCode();
!       return hash;
     }
  
     public boolean equals(Object obj)
     {
!       if (this == obj) return true;
!       if (!(obj instanceof MBeanFeatureInfo)) return false;
  
!       MBeanFeatureInfo other = (MBeanFeatureInfo)obj;
!       String thisName = getName();
!       String otherName = other.getName();
!       if (thisName != null ? !thisName.equals(otherName) : otherName != null) return false;
!       String thisDescr = getDescription();
!       String otherDescr = other.getDescription();
!       if (thisDescr != null ? !thisDescr.equals(otherDescr) : otherDescr != null) return false;
!       return true;
     }
  }

Index: MBeanOperationInfo.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/MBeanOperationInfo.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** MBeanOperationInfo.java	7 Sep 2004 12:44:16 -0000	1.11
--- MBeanOperationInfo.java	5 Oct 2004 09:46:20 -0000	1.12
***************
*** 133,139 ****
  
        String type = getReturnType();
!       hash ^= type == null ? 0 : type.hashCode();
! 
!       hash ^= Utils.arrayHashCode(getSignature());
  
        return hash;
--- 133,139 ----
  
        String type = getReturnType();
!       if (type != null) hash = 29 * hash + type.hashCode();
!       hash = 29 * hash + Utils.arrayHashCode(getSignature());
!       hash = 29 * hash + getImpact();
  
        return hash;
***************
*** 143,164 ****
     {
        if (!super.equals(obj)) return false;
  
!       try
!       {
!          MBeanOperationInfo other = (MBeanOperationInfo)obj;
! 
!          String type = getReturnType();
!          String otherType = other.getReturnType();
!          if (type != null && !type.equals(otherType)) return false;
!          if (type == null && otherType != null) return false;
  
!          // No checks on description and impact
  
!          return Utils.arrayEquals(getSignature(), other.getSignature());
!       }
!       catch (ClassCastException ignored)
!       {
!       }
!       return false;
     }
  }
--- 143,157 ----
     {
        if (!super.equals(obj)) return false;
+       if (!(obj instanceof MBeanOperationInfo)) return false;
  
!       MBeanOperationInfo other = (MBeanOperationInfo)obj;
  
!       String thisType = getReturnType();
!       String otherType = other.getReturnType();
!       if (thisType != null ? !thisType.equals(otherType) : otherType != null) return false;
!       if (!Utils.arrayEquals(getSignature(), other.getSignature())) return false;
!       if (getImpact() != other.getImpact()) return false;
  
!       return true;
     }
  }

Index: MBeanAttributeInfo.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/MBeanAttributeInfo.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** MBeanAttributeInfo.java	7 Sep 2004 12:44:16 -0000	1.12
--- MBeanAttributeInfo.java	5 Oct 2004 09:46:19 -0000	1.13
***************
*** 137,146 ****
        int hash = super.hashCode();
  
!       String type = getType();
!       hash ^= type == null ? 0 : type.hashCode();
  
!       hash ^= isReadable() ? Boolean.TRUE.hashCode() : Boolean.FALSE.hashCode();
!       hash ^= isWritable() ? Boolean.TRUE.hashCode() : Boolean.FALSE.hashCode();
!       hash ^= isIs() ? Boolean.TRUE.hashCode() : Boolean.FALSE.hashCode();
  
        return hash;
--- 137,146 ----
        int hash = super.hashCode();
  
!       String t = getType();
!       if (t != null) hash = 29 * hash + t.hashCode();
  
!       hash = 29 * hash + 3 * (isReadable() ? Boolean.TRUE.hashCode() : Boolean.FALSE.hashCode());
!       hash = 29 * hash + 5 * (isWritable() ? Boolean.TRUE.hashCode() : Boolean.FALSE.hashCode());
!       hash = 29 * hash + 7 * (isIs() ? Boolean.TRUE.hashCode() : Boolean.FALSE.hashCode());
  
        return hash;
***************
*** 150,173 ****
     {
        if (!super.equals(obj)) return false;
  
!       try
!       {
!          MBeanAttributeInfo other = (MBeanAttributeInfo)obj;
  
!          String type = getType();
!          String otherType = other.getType();
!          if (type != null && !type.equals(otherType)) return false;
!          if (type == null && otherType != null) return false;
  
!          if (isReadable() ^ other.isReadable()) return false;
!          if (isWritable() ^ other.isWritable()) return false;
!          if (isIs() ^ other.isIs()) return false;
  
!          return true;
!       }
!       catch (ClassCastException ignored)
!       {
!       }
!       return false;
     }
  
--- 150,166 ----
     {
        if (!super.equals(obj)) return false;
+       if (!(obj instanceof MBeanAttributeInfo)) return false;
  
!       MBeanAttributeInfo other = (MBeanAttributeInfo)obj;
  
!       String thisType = getType();
!       String otherType = other.getType();
!       if (thisType != null ? !thisType.equals(otherType) : otherType != null) return false;
  
!       if (isReadable() ^ other.isReadable()) return false;
!       if (isWritable() ^ other.isWritable()) return false;
!       if (isIs() ^ other.isIs()) return false;
  
!       return true;
     }
  

Index: MBeanNotificationInfo.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/MBeanNotificationInfo.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** MBeanNotificationInfo.java	7 Sep 2004 12:44:16 -0000	1.11
--- MBeanNotificationInfo.java	5 Oct 2004 09:46:20 -0000	1.12
***************
*** 65,69 ****
     public int hashCode()
     {
!       return super.hashCode() ^ Utils.arrayHashCode(getNotifTypes());
     }
  
--- 65,69 ----
     public int hashCode()
     {
!       return super.hashCode() + 29 * Utils.arrayHashCode(getNotifTypes());
     }
  
***************
*** 71,84 ****
     {
        if (!super.equals(obj)) return false;
  
!       try
!       {
!          MBeanNotificationInfo other = (MBeanNotificationInfo)obj;
!          return Utils.arrayEquals(getNotifTypes(), other.getNotifTypes());
!       }
!       catch (ClassCastException ignored)
!       {
!       }
!       return false;
     }
  }
--- 71,78 ----
     {
        if (!super.equals(obj)) return false;
+       if (!(obj instanceof MBeanNotificationInfo)) return false;
  
!       MBeanNotificationInfo other = (MBeanNotificationInfo)obj;
!       return Utils.arrayEquals(getNotifTypes(), other.getNotifTypes());
     }
  }

Index: MBeanParameterInfo.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/MBeanParameterInfo.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** MBeanParameterInfo.java	7 Sep 2004 12:44:16 -0000	1.9
--- MBeanParameterInfo.java	5 Oct 2004 09:46:20 -0000	1.10
***************
*** 66,71 ****
     {
        int hash = super.hashCode();
!       String type = getType();
!       hash ^= type == null ? 0 : type.hashCode();
        return hash;
     }
--- 66,71 ----
     {
        int hash = super.hashCode();
!       String t = getType();
!       if (t != null) hash = 29 * hash + t.hashCode();
        return hash;
     }
***************
*** 74,91 ****
     {
        if (!super.equals(obj)) return false;
  
!       try
!       {
!          MBeanParameterInfo other = (MBeanParameterInfo)obj;
!          String type = getType();
!          String otherType = other.getType();
!          if (type != null && !type.equals(otherType)) return false;
!          if (type == null && otherType != null) return false;
!          return true;
!       }
!       catch (ClassCastException ignored)
!       {
!       }
!       return false;
     }
  }
--- 74,85 ----
     {
        if (!super.equals(obj)) return false;
+       if (!(obj instanceof MBeanParameterInfo)) return false;
  
!       MBeanParameterInfo other = (MBeanParameterInfo)obj;
!       String thisType = getType();
!       String otherType = other.getType();
!       if (thisType != null ? !thisType.equals(otherType) : otherType != null) return false;
! 
!       return true;
     }
  }



-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl