This patch tries to get the VM-specific code more reliably, adding the
hash code of the local host string.

2006-03-08  Audrius Meskauskas  <[EMAIL PROTECTED]>

   * java/rmi/server/UID.java (getMachineId): Include the host IP address.
Index: UID.java
===================================================================
RCS file: /sources/classpath/classpath/java/rmi/server/UID.java,v
retrieving revision 1.9
diff -u -r1.9 UID.java
--- UID.java	8 Mar 2006 07:57:02 -0000	1.9
+++ UID.java	8 Mar 2006 21:38:24 -0000
@@ -42,6 +42,7 @@
 import java.io.DataOutput;
 import java.io.IOException;
 import java.io.Serializable;
+import java.net.InetAddress;
 
 /**
  * Represents the unique identifier over time for the host which has generated
@@ -187,10 +188,26 @@
    */
   static int getMachineId()
   {
+    int hostIpHash;
+
+    try
+      {
+        // Try to get the host IP.
+        String host = InetAddress.getLocalHost().toString();
+        // This hash is content - based, not the address based.
+        hostIpHash = host.hashCode();
+      }
+    catch (Exception e)
+      {
+        // Failed due some reason.
+        hostIpHash = 0;
+      }
+
     // Should be the unque address if hashcodes are addresses.
     // Additionally, add the time when the RMI system was probably started
     // (this class was first instantiated).
-    return UID.class.hashCode() + (int) System.currentTimeMillis();
+    return new Object().hashCode() ^ (int) System.currentTimeMillis()
+           ^ hostIpHash;
   }
   
   /**

Reply via email to