fix #7219 fixing wrong handling of proxies which are hidden in collections (bug fix 3)
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Thu, 25 Jan 2018 16:53:50 +0000 (17:53 +0100)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Thu, 25 Jan 2018 16:53:50 +0000 (17:53 +0100)
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CacheLoader.java

index 789e433020a8efd589f75dc61053f0e30b3ebc95..c7c7a15c2a670a1adc25ab0c9490f43993646d7e 100644 (file)
@@ -301,30 +301,35 @@ public class CacheLoader {
         // since there could be new or deleted objects in the cdmEntity sub-graph
 
         // start by getting the fields from the cdm entity
-        String className = ProxyUtils.deproxy(cdmEntity).getClass().getName();
-        CdmModelFieldPropertyFromClass cmgmfc = getFromCdmlibModelCache(className);
-        if(cmgmfc != null) {
-            alreadyVisitedEntities.add(cdmEntity);
-            List<String> fields = cmgmfc.getFields();
-            for(String field : fields) {
-                // 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
-
-                CdmBase cdmEntityInSubGraph = getCdmBaseTypeFieldValue(cdmEntity, cachedCdmEntity, field, alreadyVisitedEntities, update);
-                if(cdmEntityInSubGraph != null) {
-                    //checkForIdenticalCdmEntity(alreadyVisitedEntities, cdmEntityInSubGraph);
-                    if(!checkForIdenticalCdmEntity(alreadyVisitedEntities, cdmEntityInSubGraph)) {
-                        logger.debug("recursive loading object of type " + cdmEntityInSubGraph.getClass().getName() + " with id " + cdmEntityInSubGraph.getId());
-                        loadRecursive(cdmEntityInSubGraph, alreadyVisitedEntities, update);
-                    } else {
-                        logger.debug("object of type " + cdmEntityInSubGraph.getClass().getName() + " with id " + cdmEntityInSubGraph.getId() + " already visited");
+        CdmBase deproxiedEntity = (CdmBase)ProxyUtils.deproxyOrNull(cdmEntity);
+        if(deproxiedEntity != null){
+            String className = deproxiedEntity.getClass().getName();
+            CdmModelFieldPropertyFromClass cmgmfc = getFromCdmlibModelCache(className);
+            if(cmgmfc != null) {
+                alreadyVisitedEntities.add(cdmEntity);
+                List<String> fields = cmgmfc.getFields();
+                for(String field : fields) {
+                    // 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
+
+                    CdmBase cdmEntityInSubGraph = getCdmBaseTypeFieldValue(deproxiedEntity, cachedCdmEntity, field, alreadyVisitedEntities, update);
+                    if(cdmEntityInSubGraph != null) {
+                        //checkForIdenticalCdmEntity(alreadyVisitedEntities, cdmEntityInSubGraph);
+                        if(!checkForIdenticalCdmEntity(alreadyVisitedEntities, cdmEntityInSubGraph)) {
+                            logger.debug("recursive loading object of type " + cdmEntityInSubGraph.getClass().getName() + " with id " + cdmEntityInSubGraph.getId());
+                            loadRecursive(cdmEntityInSubGraph, alreadyVisitedEntities, update);
+                        } else {
+                            logger.debug("object of type " + cdmEntityInSubGraph.getClass().getName() + " with id " + cdmEntityInSubGraph.getId() + " already visited");
+                        }
                     }
                 }
+            } else {
+                throw new CdmClientCacheException("CdmEntity with class " + cdmEntity.getClass().getName() + " is not found in the cdmlib model cache. " +
+                        "The cache may be corrupted or not in sync with the latest model version" );
             }
         } else {
-            throw new CdmClientCacheException("CdmEntity with class " + cdmEntity.getClass().getName() + " is not found in the cdmlib model cache. " +
-                    "The cache may be corrupted or not in sync with the latest model version" );
+            logger.debug("ignoring uninitlialized proxy " + cdmEntity.getClass() + "#" + cdmEntity.getId());
         }
 
         return cachedCdmEntity;