(fix) O3-5607: Prevent NPE when assignTicket payload fields are missing#110
Open
sanks011 wants to merge 2 commits into
Open
(fix) O3-5607: Prevent NPE when assignTicket payload fields are missing#110sanks011 wants to merge 2 commits into
sanks011 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a NullPointerException in the legacy /queueutil/assignticket endpoint when expected JSON fields are missing or null, so the endpoint returns a 400 instead of crashing with a 500.
Changes:
- Replaced
actualObj.get(...).textValue()withactualObj.path(...).asText("")for safer JSON field extraction. - Ensures missing/null payload fields fall through to existing required-field validation (
isEmpty()-> 400).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…rmed JSON handling, and unit tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirements
Summary
This PR fixes a critical
NullPointerException(HTTP 500 API crash) and completes hardening of theLegacy1xRestController/assignTicketToServicePointendpoint. Three issues were addressed based on Copilot AI review:1. NullPointerException on missing JSON keys (original bug)
Jackson's
get(property)returnsnullfor missing fields — calling.textValue()or.isEmpty()onnullcrashed the endpoint.2. Silent type coercion (Copilot comment 1)
The initial fix used
asText("")which would coerce non-string types (e.g.{"status": 123}) into valid strings, violating the API contract. Now using explicitisTextual()+isMissingNode()+isNull()checks per Copilot's suggestion — non-string values are now rejected with400.3. Malformed JSON body crash (Copilot comment 2)
mapper.readTree("")throwsJsonProcessingExceptionfor blank or garbage input, which bubbled up as a500. Now caught and returned as400 Bad Request.4. Unit tests added (Copilot comment 3)
Added
Legacy1xRestControllerAssignTicketTestcovering 8 scenarios: empty body, invalid JSON, missing fields, explicitnullvalues, non-string types, empty strings, and the valid happy path.Related Issue
https://issues.openmrs.org/browse/O3-5607
Other
No UI changes. Backend only.