BUG-5504: use Object.toString() without overrides in precondition 90/36290/2
authorRobert Varga <rovarga@cisco.com>
Wed, 16 Mar 2016 12:57:17 +0000 (13:57 +0100)
committerRobert Varga <nite@hq.sk>
Tue, 29 Mar 2016 08:48:05 +0000 (08:48 +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>
(cherry picked from commit 414ea232f11da87dbdfbb1a7a10155b93e93b853)

yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTree.java

index 13070428ec896c1722f01454bdd2841a4b25fcab..6e389699294b1decde70ce35484ae0d3efcd2a05 100644 (file)
@@ -113,13 +113,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;