Handle Null Pointer Exception
I made a generic enum and used mapstruct, my code is working nice, but having a null points warning
My BaseEnum Interface below;
public interface ValueRedable { static <T extends Enum<T> & ValueReadable> T getEnumByValue(Class<T> emunType, Object value) { for (T item : enumType.getEnumConstants()) { if (item.getValue() == value) { return item; } } return null; } } Object getValue(); String getDescription(); }
my Enum Class Below;
@Getter @AllArgsConstructor(access = AccessLevel.PRIVATE) public enum TestStatus implements ValueReadable { STH(1, "sth") private final Integer value; private final String description; @Override //// /// }
My Mapper Class Below
@AferMapping void sth /////.... ValueReadbale.getEnumByValue(TestStatus.clas,, .. sth).getDescription());
it says; Method invocation ‘getDescription()’ may produce NullPointerException so how can I handle this problem?
Thank you