Skip to content

Fix operator precedence bug in getRefByUuid() exception message#6351

Open
Kapil-kundu wants to merge 2 commits into
openmrs:masterfrom
Kapil-kundu:master
Open

Fix operator precedence bug in getRefByUuid() exception message#6351
Kapil-kundu wants to merge 2 commits into
openmrs:masterfrom
Kapil-kundu:master

Conversation

@Kapil-kundu

Copy link
Copy Markdown

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

  • Generates the correct error message.
  • Prevents incorrect evaluation of the ternary expression.
  • Avoids a possible NullPointerException when type is null.

JIra Ticker : https://openmrs.atlassian.net/browse/TRUNK-6714

@sonarqubecloud

Copy link
Copy Markdown

@Kapil-kundu

Copy link
Copy Markdown
Author

@jwnasambu please review the changes

@jwnasambu jwnasambu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 jwnasambu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@Kapil-kundu

Copy link
Copy Markdown
Author

@jwnasambu can I write test cases only for my changes or should I have to write all the test cases for the files

@jwnasambu

Copy link
Copy Markdown
Contributor

@Kapil-kundu Kindly write test cases only for the changes you made.

@Kapil-kundu
Kapil-kundu requested a review from jwnasambu July 20, 2026 09:39
@Kapil-kundu

Copy link
Copy Markdown
Author

@jwnasambu test cases added for what I changed

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.

3 participants