summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamjan Jovanovic <damjan@apache.org>2017-08-20 06:22:29 +0000
committerAndras Timar <andras.timar@collabora.com>2021-12-13 20:58:54 +0100
commit36f1060e3c5be0946cd1bc811b84cc542fafe70b (patch)
treeb3238993bd52e4fb54822503e0621692ef553ea9
parent4a92919c5b1f94ccc58acc01ad3fb40961fce7ad (diff)
i#32546# - Java UnoRuntime.getUniqueKey/generateOid do not work reliablydistro/collabora/libreoffice-4.0.6.2
In the Java UNO bridge, UnoRuntime.generateOid() generated the object-specific part of the OID using java.lang.Object.hashCode(), which is only 32 bits long, and is commonly overriden and could thus return values from an even smaller range, so OID collisions were quite likely. This changes UnoRuntime.generateOid() to use 128 bit UUIDs for the object-specific part of the OID, and store these in an object => oid java.util.WeakHashMap, making OID collisions almost impossible. Patch by: me Suggested by: Stephan Bergmann (stephan dot bergmann dot secondary at googlemail dot com) (cherry picked from commit 6dd83d1c6c5c580d14ca3d0458be4020603ba118) Change-Id: I8e851a7a69ac2defefa15e9a00118d8f9fc0da95 Reviewed-on: https://gerrit.libreoffice.org/41576 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r--ridljar/com/sun/star/uno/UnoRuntime.java14
1 files changed, 13 insertions, 1 deletions
diff --git a/ridljar/com/sun/star/uno/UnoRuntime.java b/ridljar/com/sun/star/uno/UnoRuntime.java
index a2fb84848da4..0d3ae0b01d48 100644
--- a/ridljar/com/sun/star/uno/UnoRuntime.java
+++ b/ridljar/com/sun/star/uno/UnoRuntime.java
@@ -23,6 +23,8 @@ import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.UUID;
+import java.util.WeakHashMap;
import com.sun.star.lib.uno.typedesc.TypeDescription;
import com.sun.star.lib.util.WeakMap;
@@ -104,7 +106,16 @@ public class UnoRuntime {
if (object instanceof IQueryInterface) {
oid = ((IQueryInterface) object).getOid();
}
- return oid == null ? object.hashCode() + oidSuffix : oid;
+ if (oid == null) {
+ synchronized (oidMap) {
+ oid = oidMap.get(object);
+ if (oid == null) {
+ oid = UUID.randomUUID().toString() + oidSuffix;
+ oidMap.put(object, oid);
+ }
+ }
+ }
+ return oid;
}
/**
@@ -673,6 +684,7 @@ public class UnoRuntime {
private final IBridge bridge;
}
+ private static final WeakHashMap<Object,String> oidMap = new WeakHashMap<Object,String>();
private static final String uniqueKeyHostPrefix
= Integer.toString(new Object().hashCode(), 16) + ":";
private static final Object uniqueKeyLock = new Object();