#4018 fix NPE in DefaultTermComparator
authorKatja Luther <k.luther@bgbm.org>
Wed, 29 Jun 2016 07:43:07 +0000 (09:43 +0200)
committerKatja Luther <k.luther@bgbm.org>
Wed, 29 Jun 2016 07:43:07 +0000 (09:43 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/DefaultTermComparator.java

index 16c07dfc94a28de8aad4ddcbd6c0677db02e4496..5918cda845a3ba126fc62521e56e78a2d0096d08 100644 (file)
@@ -26,6 +26,15 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
 public class DefaultTermComparator<T extends DefinedTermBase> implements Comparator<T> {
        @Override
        public int compare(T o1, T o2) {
+               if (o1 == o2){
+                       return 0;
+               }
+               if (o1 == null){
+                       return -1;
+               }
+               if (o2 == null){
+                       return 1;
+               }
                String label1 = o1.getLabel(CdmStore.getDefaultLanguage()) != null ? o1.getLabel(CdmStore.getDefaultLanguage()) : o1.getTitleCache();
                String label2 = o2.getLabel(CdmStore.getDefaultLanguage()) != null ? o2.getLabel(CdmStore.getDefaultLanguage()) : o2.getTitleCache();
                return label1.compareTo(label2);