Fix potential NPE
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 27 Jun 2016 10:34:16 +0000 (12:34 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 27 Jun 2016 10:37:51 +0000 (12:37 +0200)
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java

index 9d66a112f086a73252802824fe308642bae0569c..61e8b1d73292d7cd2f5c449388e8832d33adf80a 100644 (file)
@@ -66,25 +66,28 @@ public class NavigationUtil extends AbstractUtility{
         */
        public static void openEditor(UuidAndTitleCache uuidAndTitleCache){
            Class type = uuidAndTitleCache.getType();
+           ICdmBase cdmBase = null;
            if(type.equals(Classification.class)){
-               Classification classification = CdmStore.getService(IClassificationService.class).load(uuidAndTitleCache.getUuid());
-               openEditor(classification);
+               cdmBase = CdmStore.getService(IClassificationService.class).load(uuidAndTitleCache.getUuid());
            }
            else if(type.equals(TaxonNode.class)){
-               TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(uuidAndTitleCache.getUuid());
-               openEditor(taxonNode);
+               cdmBase = CdmStore.getService(ITaxonNodeService.class).load(uuidAndTitleCache.getUuid());
            }
            else if(TaxonBase.class.isAssignableFrom(type)){
-               TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).load(uuidAndTitleCache.getUuid());
-               openEditor(taxonBase);
+               cdmBase = CdmStore.getService(ITaxonService.class).load(uuidAndTitleCache.getUuid());
            }
            else if(type.equals(TaxonNameBase.class)){
-               TaxonNameBase nameBase = CdmStore.getService(INameService.class).load(uuidAndTitleCache.getUuid());
-               openEditor(nameBase);
+               cdmBase = CdmStore.getService(INameService.class).load(uuidAndTitleCache.getUuid());
            }
            else{
                MessagingUtils.warningDialog("Unknown type", NavigationUtil.class, "There is no editor available to open this object.");
            }
+           if(cdmBase!=null){
+               openEditor(cdmBase);
+           }
+           else{
+               MessagingUtils.warningDialog("Cdm entity not found", NavigationUtil.class, "CDM entity could not be found in the database.");
+           }
        }
 
        public static void openEditor(ICdmBase selectedObject){