From 0f729503369e43eb8dffb383a74c560675cc277b Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 26 Sep 2024 09:48:12 +0200 Subject: [PATCH] fix NPE in DisplayAs --- .../java/net/hostsharing/hsadminng/errors/DisplayAs.java | 9 +++++++-- .../hsadminng/persistence/EntityExistsValidator.java | 2 -- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/errors/DisplayAs.java b/src/main/java/net/hostsharing/hsadminng/errors/DisplayAs.java index 8eba1c13..20723330 100644 --- a/src/main/java/net/hostsharing/hsadminng/errors/DisplayAs.java +++ b/src/main/java/net/hostsharing/hsadminng/errors/DisplayAs.java @@ -9,7 +9,9 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface DisplayAs { + class DisplayName { + public static String of(final Class clazz) { final var displayNameAnnot = getDisplayNameAnnotation(clazz); return displayNameAnnot != null ? displayNameAnnot.value() : clazz.getSimpleName(); @@ -20,8 +22,11 @@ public @interface DisplayAs { } private static DisplayAs getDisplayNameAnnotation(final Class clazz) { - final var annot = clazz.getAnnotation(DisplayAs.class); - return annot != null ? annot : getDisplayNameAnnotation(clazz.getSuperclass()); + if (clazz == null) { + return null; + } + final var annot = clazz.getAnnotation(DisplayAs.class); + return annot != null ? annot : getDisplayNameAnnotation(clazz.getSuperclass()); } } diff --git a/src/main/java/net/hostsharing/hsadminng/persistence/EntityExistsValidator.java b/src/main/java/net/hostsharing/hsadminng/persistence/EntityExistsValidator.java index df0e8637..fac98d33 100644 --- a/src/main/java/net/hostsharing/hsadminng/persistence/EntityExistsValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/persistence/EntityExistsValidator.java @@ -1,7 +1,5 @@ package net.hostsharing.hsadminng.persistence; -import lombok.experimental.UtilityClass; -import net.hostsharing.hsadminng.errors.DisplayAs; import net.hostsharing.hsadminng.errors.DisplayAs.DisplayName; import net.hostsharing.hsadminng.rbac.object.BaseEntity; import org.springframework.beans.factory.annotation.Autowired;