fix(vmcomponents): handle NPE and ClassCastException in getVulIdsPerComponentVmId#3780
Open
Shivamrut wants to merge 2 commits intoeclipse-sw360:mainfrom
Open
fix(vmcomponents): handle NPE and ClassCastException in getVulIdsPerComponentVmId#3780Shivamrut wants to merge 2 commits intoeclipse-sw360:mainfrom
Shivamrut wants to merge 2 commits intoeclipse-sw360:mainfrom
Conversation
…omponentVmId fixes eclipse-sw360#2726 Signed-off-by: Shivamrut <gshivamrut@gmail.com>
Member
|
@akshitjoshii please help test this PR. |
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.
Summary
Fixes #2726 — SVM notifications are silently not updated after the
json-simplelibrary upgrade in commitcd53eed.Root Cause
The bug was introduced when
json-simplewas upgraded to version 4.x (cd53eed). Two breaking changes affectedgetVulIdsPerComponentVmIdinSVMSyncHandler.java:1. NullPointerException — when the SVM API returns a JSON object that is missing the
"id"field,json.get(VULNERABILITY_ID)returnsnull. The old code called.toString()directly on that result:2. ClassCastException —
json-simple 4.xnow parses plain integers in a JSON array asBigDecimal(previouslyLong). The old code unconditionally cast every array element toJsonObject:Both exceptions were caught by the surrounding
catch (RuntimeException e)block and silently swallowed, returning an empty set. This caused vulnerability notifications to never be updated — exactly the symptom reported in #2726.Fix
JsonObject, extract the"id"field safely with a null check.BigDecimal,String, etc.), callid.toString()directly.Why the Bug Was Not Reproduced Live
Reproducing this bug end-to-end requires a live SVM API endpoint (Siemens internal). Without access to that endpoint, the sync process fails at the HTTP request stage before ever reaching the buggy line. Instead, the bug was confirmed through:
VMProcessor→SVMSyncHandler.getVulnerabilitiesByComponentId→getVulIdsPerComponentVmId, confirming the exact lines that throw.json-simplelibrary level (no SVM access needed).Tests
A new standalone test class
SVMSyncHandlerVulIdsTestwas added. It requires no CouchDB and no SVM endpoint — WireMock fakes the HTTP responses and Mockito mocks the DB handler.rootCause_JsonObjectMissingKey_..._ThrowsNPEjson.get("id")returnsnullfor a missing key;.toString()throws NPE. Directly replicates the old buggy line.rootCause_PlainInteger_..._ThrowsClassCastExceptionjson-simple 4.xparses integers asBigDecimal; casting toJsonObjectthrowsClassCastException.testGetVulIds_ObjectsWithIdField_ReturnsVulIds"id"field return 3 IDs correctly.testGetVulIds_ObjectWithMissingIdField_ReturnsEmptyGracefully"id"field returns empty set without exception.testGetVulIds_PlainIntegerIds_ReturnsVulIdsassertEquals(3, result.size())fails on old code, passes on fix.All 5 tests pass:
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0