Menu

2 unequal CIMInstances with the same hashcode

Help
JC
2004-01-13
2004-01-14
  • JC

    JC - 2004-01-13

    I'm using v0.97 and wrote a small piece of code that reports 2 CIMInstances as being unequal, but having the same hashcode() values.  Is this normal?  or perhaps a bug that I should file?

    Here's a code snippet:
        private Set getTopLevelComputerSystems() throws CIMException {
            CIMObjectPath cop = new CIMObjectPath(COMPUTERSYSTEM);
            HashSet resultSet = new HashSet();
            Vector v = new Vector();
            if (m_cimClient.getClass(cop) != null) {
                Enumeration eCS = m_cimClient.enumerateInstances(cop, false);
                CIMInstance compInst = null;
                Enumeration eParent = null;
                while (eCS.hasMoreElements()) {
                    compInst = (CIMInstance) eCS.nextElement();
                    // Refer to Section 7.3.3.3.8.1 of the SMI-S spec on how this is done
                    eParent = m_cimClient.associatorNames(compInst.getObjectPath(), COMPONENTCS,
                            COMPUTERSYSTEM, null, GROUPCOMPONENT);
                    if (!eParent.hasMoreElements()) {  // are there no parents for this objectpath?  if so, it's a top-level
                        resultSet.add(compInst);
                        v.add(compInst);
                    }
                }
            }
            // let's check this weird oddity
            System.out.println(v.get(0));
            System.out.println(v.get(1));
            System.out.println("Are these instances equal?? " + (v.get(0) == v.get(1)));
            System.out.println("HashCode for [0] = " + v.get(0).hashCode() + "  HashCode for [1] = " + v.get(1).hashCode());
            System.out.println("Total found = " + resultSet.size());
            return resultSet;
        }

    The results I get is this:
    instance of XXXXX_StorageSystem {
        Licenses = "Basic";
         DeviceAdditionalPolicy = "manual";
         ConsoleLunID = null;
         ElementRefreshStatus = "0,6,0,16,2,0,0,3208,0,5,0,0";
         TotalStorageSpace = "473.82";
         UsedStorageSpace = "247.76";
         AvailableStorageSpace = "226.06";
         DRMCellConnections = {};
         ManagementStation = "15.43.211.45";
         VolumeReplacementDelay = "60";
         FirmwareVersion = "3010";
         ControllerTime = "12-01-2004   18:54:12";
         ElementName = "COMPAQ RING";
         Comment = null;
    };
    instance of XXXXX_StorageSystem {
        Licenses = "Basic,DRM,Snapshot";
         DeviceAdditionalPolicy = "manual";
         ConsoleLunID = null;
         ElementRefreshStatus = "0,10,0,34,22,2,0,5905,0,9,0,11";
         TotalStorageSpace = "270.82";
         UsedStorageSpace = "237.54";
         AvailableStorageSpace = "33.28";
         DRMCellConnections = {};
         ManagementStation = "15.43.211.45";
         VolumeReplacementDelay = "60";
         FirmwareVersion = "3010";
         ControllerTime = "12-01-2004   19:02:06";
         ElementName = "XXX100_43F0";
         Comment = null;
    };
    Are these instances equal?? false
    HashCode for [0] = -747749325  HashCode for [1] = -747749325 Total found = 1

    Notice I have 2 different entries with the same hashcode.  As a result, I cannot put these 2 CIMInstances as separate elements in a regular HashSet.

     
    • Brian Schlosser

      Brian Schlosser - 2004-01-14

      Jim had brought it up before, but I don't know what it's status is. Why don't you open up a bug for it so that we make sure to track it.

      Brian

       
    • JC

      JC - 2004-01-14

      Bug 877009 has been submitted regarding this problem.  Thanks

       

Log in to post a comment.