fix NPE in DisplayAs

This commit is contained in:
Michael Hoennig 2024-09-26 09:48:12 +02:00
parent b571a911f7
commit 0f72950336
2 changed files with 7 additions and 4 deletions

View File

@ -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());
}
}

View File

@ -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;