BUG-5504: use Object.toString() without overrides in precondition 88/36288/2
authorRobert Varga <rovarga@cisco.com>
Wed, 16 Mar 2016 12:57:17 +0000 (13:57 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 21 Mar 2016 10:38:34 +0000 (10:38 +0000)
The precondition check could end up using a lot of memory due to dump of the
data tree. Implement a simpler version and use that in the message.

Change-Id: I494cb92c7f4691d235e8ffac6f79c696e4ea0f48
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTree.java

index 95165371c32c4491838da01c2d25cf51ce54277d..f7bce41d6b60dbb1443dd978de5778008ba055d4 100644 (file)
@@ -114,13 +114,21 @@ final class InMemoryDataTree extends AbstractDataTreeTip implements TipProducing
             LOG.debug("Updating datastore from {} to {}", currentRoot, newRoot);
 
             final TreeNode oldRoot = c.getBeforeRoot();
-            Preconditions.checkState(oldRoot == currentRoot, "Store tree %s and candidate base %s differ.", currentRoot, oldRoot);
+            if (oldRoot != currentRoot) {
+                final String oldStr = simpleToString(oldRoot);
+                final String currentStr = simpleToString(currentRoot);
+                throw new IllegalStateException("Store tree " + currentStr + " and candidate base " + oldStr + " differ.");
+            }
 
             newState = currentState.withRoot(newRoot);
             LOG.trace("Updated state from {} to {}", currentState, newState);
         } while (!STATE_UPDATER.compareAndSet(this, currentState, newState));
     }
 
+    private static String simpleToString(final Object o) {
+        return o.getClass().getName() + "@" + Integer.toHexString(o.hashCode());
+    }
+
     @Override
     public YangInstanceIdentifier getRootPath() {
         return rootPath;