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

Asked on July 16, 2020 in Java.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.