Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRUNK-5564:PersonAddressValidator - Throws exception instead of logging #3041

Closed
wants to merge 1 commit into from
Closed

Conversation

jwnasambu
Copy link
Contributor

Description of what I changed

Issue I worked on

https://issues.openmrs.org/browse/TRUNK-5564
I coded the PersonAddressValidator in a way that avoids throwing exceptions

@coveralls
Copy link

coveralls commented Oct 30, 2019

Coverage Status

Coverage increased (+0.003%) to 59.958% when pulling 05068d9 on jwnasambu:TRUNK-5564 into 8b04b19 on openmrs:master.

@@ -64,7 +64,7 @@ public void validate(Object object, Errors errors) {
}

if (object == null) {
throw new IllegalArgumentException("The personAddress object should not be null");
errors.reject("error.Address");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the needs of your ticket,i see you need to use some logging and cannot see it here

Copy link
Member

@Akayeshmantha Akayeshmantha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @jwnasambu

Julie just use the logger defined in the class scope like below

if (obj == null) { log.error("Address object contains null value (in youre words)"); return; }

@jwnasambu
Copy link
Contributor Author

@Ayesh I have made the changes. Thanks

@@ -64,7 +64,8 @@ public void validate(Object object, Errors errors) {
}

if (object == null) {
throw new IllegalArgumentException("The personAddress object should not be null");
log.error("Address object contains null value");
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need the return i see your method is a void!!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably needed. Previously the code would not continue in this method because of the throw, this change now logs and returns instead. Thus, the explicit "return;" is needed to exit the method early; without it execution would continue in the function and a NullPointerException would likely follow.

@Akayeshmantha
Copy link
Member

Akayeshmantha commented Nov 11, 2019

Nice work @jwamalwa
Resolve the review comments

@dkayiwa can we merge this PR

@dkayiwa
Copy link
Member

dkayiwa commented Nov 11, 2019

Can you follow the same pattern used by other validators? https://github.com/openmrs/openmrs-core/tree/master/api/src/main/java/org/openmrs/validator

@Akayeshmantha
Copy link
Member

@dkayiwa

The ticket says not to throw the exception.

For example this validator does the same as @jwamalwa does for this validator and it's good to have a logging message for reference as well so I don't see anything to change here :

https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/validator/PatientValidator.java

@dkayiwa
Copy link
Member

dkayiwa commented Nov 13, 2019

@Akayeshmantha did you look at the validators in the link that i gave?

@Akayeshmantha
Copy link
Member

Hmm yes, @dkayiwa . The one I posted in the previous comment is also a validator in the same link

@dkayiwa
Copy link
Member

dkayiwa commented Nov 13, 2019

@Akayeshmantha how many validators did you look at?

@jwnasambu
Copy link
Contributor Author

@dkayiwa, @Akayeshmantha I have made some changes kindly review my PR and feel free to advice me.

@dkayiwa
Copy link
Member

dkayiwa commented Nov 13, 2019

@jwnasambu did you take a look at the validators that i pointed to?

@jwnasambu
Copy link
Contributor Author

@dkayiwa yes I did only that they are several and am still going through to understand.

@Akayeshmantha
Copy link
Member

Hi @dkayiwa

Sure will go through

@jwnasambu jwnasambu closed this Nov 19, 2019
@jwnasambu jwnasambu deleted the TRUNK-5564 branch November 19, 2019 07:11
@jwnasambu jwnasambu restored the TRUNK-5564 branch November 19, 2019 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants