I have to take few actions depending upon the if condition. Say I have an enum "VoucherType"
Now I have a code, that is executed depending upon the condition:-
private boolean verifyGiveAwayAccounting(GiveAwayMoneyVerificationEvent event) {
if(event.getVoucherType().equals(VoucherType.GIVE_AWAY_MONEY_ON_SIGNUP)){
someAction();
}
return verifySystemAccountTransaction(event);
}
I have to perform someAction() if the event is of type "GIVE_AWAY_MONEY_ON_SIGNUP" . But I do not have to do anything extra is event type is anything other than "GIVE_AWAY_MONEY_ON_SIGNUP". So when I call this code I set the voucherType to "GIVE_AWAY_MONEY_ON_SIGNUP" and someAction() is executed.
But for any other type of events, I get null pointer exceptions in the if condition as I never set the voucher type as I do not want to do anything special. So in order to avoid the nullPointerException I set the Voucher code to something dummy(other voucherType values) which I never use in any conditions. I there a sophisticated way I can eliminate the nullPointerException without initializing the VoucherType in event?