Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in ServiceConfigurations resource by handling missing Account #4062

Merged
merged 2 commits into from
Jun 25, 2024

Conversation

MDeLuise
Copy link
Contributor

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:

  • PUT v1/{non-existing-scope-id}/serviceConfigurations
  • PUT v1/{non-existing-scope-id}/serviceConfigurations/{dummy-component-id}

Changes

  • Added a check to see if accountService.find(scopeId) returns null.
  • Throw KapuaEntityNotFoundException if the account is not found for the given scopeId.

…revent NPE

Throw `KapuaEntityNotFoundException` when `Account` is not found for given `scopeId` in `ServiceConfigurations` resource. This prevents `NullPointerException` when `scopeId` does not match any account.
Copy link

codecov bot commented Jun 25, 2024

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

@@              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 Coverage Δ
.../resources/v1/resources/ServiceConfigurations.java 0.00% <0.00%> (ø)

@MDeLuise MDeLuise force-pushed the fix-serviceConfigNoAccount branch from a0bdd74 to 09ac94c Compare June 25, 2024 12:47
@Coduz Coduz added the Bug This is a bug or an unexpected behaviour. Fix it! label Jun 25, 2024
@Coduz Coduz merged commit 1835162 into eclipse-kapua:develop Jun 25, 2024
34 of 35 checks passed
@MDeLuise MDeLuise deleted the fix-serviceConfigNoAccount branch June 25, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is a bug or an unexpected behaviour. Fix it!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants