Fix endless loop in entity cache when opening "Inspect Active Session"
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 16 Aug 2016 09:56:39 +0000 (11:56 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 16 Aug 2016 09:56:39 +0000 (11:56 +0200)
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/EntityCacherDebugResult.java

index 3390ddf2aaef98c63ae1ba8b815cfb564d8dbb55..442bc6112b88e24a7899aad191f39eed6001b7e4 100644 (file)
@@ -246,10 +246,7 @@ public class EntityCacherDebugResult {
             return;
         }
 
             return;
         }
 
-        int originalMapSize = map.size();
-
         Iterator<Map.Entry<T,T>> iter = map.entrySet().iterator();
         Iterator<Map.Entry<T,T>> iter = map.entrySet().iterator();
-        int i=0;
         while ( iter.hasNext() ) {
             Map.Entry<T,T> e = iter.next();
             CdmEntityInfo childCei = new CdmEntityInfo(e);
         while ( iter.hasNext() ) {
             Map.Entry<T,T> e = iter.next();
             CdmEntityInfo childCei = new CdmEntityInfo(e);
@@ -268,15 +265,22 @@ public class EntityCacherDebugResult {
     private <T extends Object> void debug(Collection<T> collection,
             List<CdmEntityInfo> alreadyVisitedEntities,
             CdmEntityInfo cei) {
     private <T extends Object> void debug(Collection<T> collection,
             List<CdmEntityInfo> alreadyVisitedEntities,
             CdmEntityInfo cei) {
-        int length = collection.size();
-        Object[] result = new Object[length];
         Iterator<T> collectionItr = collection.iterator();
 
         while(collectionItr.hasNext()) {
             Object obj = collectionItr.next();
         Iterator<T> collectionItr = collection.iterator();
 
         while(collectionItr.hasNext()) {
             Object obj = collectionItr.next();
-            CdmEntityInfo childCei = new CdmEntityInfo(ProxyUtils.deproxy(obj));
-            cei.addChild(childCei);
-            debugRecursive(obj, alreadyVisitedEntities, childCei);
+            boolean alreadyVisited = false;
+            for (CdmEntityInfo entityInfo: alreadyVisitedEntities) {
+                if(obj.equals(entityInfo.getObject())){
+                    alreadyVisited = true;
+                    break;
+                }
+            }
+            if(!alreadyVisited){
+                CdmEntityInfo childCei = new CdmEntityInfo(ProxyUtils.deproxy(obj));
+                cei.addChild(childCei);
+                debugRecursive(obj, alreadyVisitedEntities, childCei);
+            }
 
         }
 
 
         }
 
@@ -312,7 +316,6 @@ public class EntityCacherDebugResult {
                 // retrieve the actual object corresponding to the field.
                 // this object will be either a CdmBase or a Collection / Map
                 // with CdmBase as the generic type
                 // retrieve the actual object corresponding to the field.
                 // this object will be either a CdmBase or a Collection / Map
                 // with CdmBase as the generic type
-                String f = field;
                 CdmEntityInfo childCei = getDebugCdmBaseTypeFieldValue(cdmEntity, field, alreadyVisitedEntities, cei);
                 if(!childCei.isProxy()) {
                     Object object = childCei.getObject();
                 CdmEntityInfo childCei = getDebugCdmBaseTypeFieldValue(cdmEntity, field, alreadyVisitedEntities, cei);
                 if(!childCei.isProxy()) {
                     Object object = childCei.getObject();
@@ -356,9 +359,6 @@ public class EntityCacherDebugResult {
             o = ProxyUtils.deproxy(o);
             CdmBase cdmEntityInSubGraph = null;
 
             o = ProxyUtils.deproxy(o);
             CdmBase cdmEntityInSubGraph = null;
 
-            boolean isHibernateProxy = false;
-            boolean isPersistentCollection = false;
-
             childCei = new CdmEntityInfo(o);
             cei.addChild(childCei);
             childCei.setField(field);
             childCei = new CdmEntityInfo(o);
             cei.addChild(childCei);
             childCei.setField(field);