Skip to content

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

Open
Kapil-kundu wants to merge 1 commit into
openmrs:masterfrom
Kapil-kundu:master
Open

Fix operator precedence bug in getRefByUuid() exception message#6351
Kapil-kundu wants to merge 1 commit 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

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.

1 participant