Fix operator precedence bug in getRefByUuid() exception message#6351
Fix operator precedence bug in getRefByUuid() exception message#6351Kapil-kundu wants to merge 2 commits into
Conversation
|
|
@jwnasambu please review the changes |
There was a problem hiding this comment.
This is a good catch, @Kapil-kundu, and it LGTM. Kindly add test coverage for the null type case in the affected getRefByUuid methods to prevent future regressions.
jwnasambu
left a comment
There was a problem hiding this comment.
Kindly also follow this link: https://openmrs.atlassian.net/wiki/spaces/docs/pages/25477199/Pull+Request+Tips to get tips on how to create a good pull request.
|
@jwnasambu can I write test cases only for my changes or should I have to write all the test cases for the files |
|
@Kapil-kundu Kindly write test cases only for the changes you made. |
|
@jwnasambu test cases added for what I changed |



The getRefByUuid() method contains an operator precedence issue in the APIException message construction:
throw new APIException("Unsupported type for getRefByUuid: " + type != null ? type.getName() : "null");Due to Java operator precedence, the ternary operator is evaluated incorrectly, causing the exception message to be wrong and potentially leading to a NullPointerException when type is null.
Proposed Fix
Wrap the ternary expression in parentheses:
throw new APIException( "Unsupported type for getRefByUuid: " + (type != null ? type.getName() : "null") );Impact
JIra Ticker : https://openmrs.atlassian.net/browse/TRUNK-6714