SONARJAVA-6268 Fix issue in primitveType() and primitiveWrapperType() when the sema is incomplete#5579
Conversation
primitveType() and primitiveWrapperType() when the sema is incompleteprimitveType() and primitiveWrapperType() when the sema is incomplete
SummaryThis PR fixes a null pointer risk in The fix is straightforward: extract the resolved type into a variable, check for null, and return null early if resolution fails. This mirrors the existing null-check pattern already present for the The PR also adds five new test cases covering the happy path and the failure scenarios when semantic resolution fails. What reviewers should knowCode changes: All logic changes are in
Testing: New tests in
What to watch for: The tests use
|
ee9bc42 to
5d915ff
Compare
|
There was a problem hiding this comment.
LGTM! ✅
The fix is correct and minimal. Both primitiveWrapperType() and primitiveType() now guard against a null return from sema.resolveType() before passing the result to sema.type(), preventing a NPE when the classpath is incomplete.
One behavioral nuance worth noting: when resolveType() returns null, the method exits early without populating the cache field, so subsequent calls re-enter the if-block and call resolveType() again. This is consistent with the pre-existing name == null early-return above it, and is harmless in the degraded-classpath scenario where this code path is reached.
|
Good fix. The null check before passing the result of The test approach is pragmatic: since reproducing a half-initialized ECJ semantic model in an integration test is essentially infeasible, using a spy to simulate the The rename of |
Thanks |




No description provided.