eclipse / kapua

Eclipse Public License 2.0
222 stars 160 forks source link

Fix NPE in `ServiceConfigurations` resource by handling missing `Account` #4062

Closed MDeLuise closed 2 months ago

MDeLuise commented 2 months ago

Description

This pull request addresses a potential NullPointerException (NPE) in the ServiceConfigurations resource of the Kapua REST API. The issue arises when the scopeId provided does not match any existing account.

Details

Currently, the ServiceConfigurations resource performs the following operation:

Account account = accountService.find(scopeId);
configurableService.setConfigValues(scopeId, account.getScopeId(), serviceComponentConfiguration.getProperties());

If the accountService.find(scopeId) method returns null, attempting to call account.getScopeId() will result in a NullPointerException.

The problem occurs specifically with the following calls:

Changes

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 16.81%. Comparing base (c2f4542) to head (09ac94c). Report is 3 commits behind head on develop.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/eclipse/kapua/pull/4062/graphs/tree.svg?width=650&height=150&src=pr&token=1P4N4CApH8&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse)](https://app.codecov.io/gh/eclipse/kapua/pull/4062?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse) ```diff @@ Coverage Diff @@ ## develop #4062 +/- ## ============================================= - Coverage 16.81% 16.81% -0.01% Complexity 22 22 ============================================= Files 2008 2008 Lines 52158 52162 +4 Branches 4395 4398 +3 ============================================= Hits 8770 8770 - Misses 42992 42996 +4 Partials 396 396 ``` | [Files](https://app.codecov.io/gh/eclipse/kapua/pull/4062?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse) | Coverage Δ | | |---|---|---| | [.../resources/v1/resources/ServiceConfigurations.java](https://app.codecov.io/gh/eclipse/kapua/pull/4062?src=pr&el=tree&filepath=rest-api%2Fresources%2Fsrc%2Fmain%2Fjava%2Forg%2Feclipse%2Fkapua%2Fapp%2Fapi%2Fresources%2Fv1%2Fresources%2FServiceConfigurations.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse#diff-cmVzdC1hcGkvcmVzb3VyY2VzL3NyYy9tYWluL2phdmEvb3JnL2VjbGlwc2Uva2FwdWEvYXBwL2FwaS9yZXNvdXJjZXMvdjEvcmVzb3VyY2VzL1NlcnZpY2VDb25maWd1cmF0aW9ucy5qYXZh) | `0.00% <0.00%> (ø)` | |