NPE correction when informing removed project in the listProjectRoles#13022
NPE correction when informing removed project in the listProjectRoles#13022Tonitzpp wants to merge 2 commits into
listProjectRoles#13022Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13022 +/- ##
============================================
+ Coverage 18.02% 18.08% +0.05%
- Complexity 16450 16705 +255
============================================
Files 5968 6037 +69
Lines 537086 542443 +5357
Branches 65961 66423 +462
============================================
+ Hits 96820 98081 +1261
- Misses 429346 433347 +4001
- Partials 10920 11015 +95
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes a NullPointerException triggered by calling the listProjectRoles API with a projectid that refers to a removed project, changing the behavior to return a parameter error instead of crashing.
Changes:
- Update
ProjectRoleManagerImpl.findProjectRolesto return an empty list whenprojectIdis null (instead of returning null). - Add explicit project existence validation in
ListProjectRolesCmd.execute()and throwInvalidParameterValueExceptionwhen the project cannot be found.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| server/src/main/java/org/apache/cloudstack/acl/ProjectRoleManagerImpl.java | Prevents null list returns from findProjectRoles when projectId is null. |
| api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/ListProjectRolesCmd.java | Validates the project exists before listing roles and throws a parameter exception when not found. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
listProjectRoles
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent a NullPointerException in the listProjectRoles API when the caller provides a projectid for a removed/non-existent project, changing the behavior to return a clear parameter error instead.
Changes:
- Validate the provided
projectIdinListProjectRolesCmd.execute()and throw anInvalidParameterValueExceptionwhen the project can’t be found. - Avoid per-role project lookup when building
ProjectRoleResponseby passing the project UUID through the response setup method. - Adjust
ProjectRoleManagerImpl.findProjectRoles()to return an empty list whenprojectIdis null (instead of returningnull).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
server/src/main/java/org/apache/cloudstack/acl/ProjectRoleManagerImpl.java |
Returns an empty list when projectId is null to reduce NPE risk from null list returns. |
api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/ListProjectRolesCmd.java |
Adds project existence validation and avoids NPE when a project has been removed by not dereferencing a null project during response building. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@blueorangutan package |
|
@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
There was a problem hiding this comment.
Pull request overview
Fixes an NPE in the listProjectRoles API when a removed project is supplied as projectid, by validating project existence up-front and avoiding repeated project lookups while building responses.
Changes:
- Validate the provided project ID in
ListProjectRolesCmd.execute()and throw anInvalidParameterValueExceptionwhen the project can’t be found. - Avoid calling
_projectService.getProject(...).getUuid()per role by reusing the resolved project UUID. - Adjust
ProjectRoleManagerImpl.findProjectRolesto return an empty list fornullproject IDs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| server/src/main/java/org/apache/cloudstack/acl/ProjectRoleManagerImpl.java | Changes project-role listing behavior for null/invalid project IDs (now returns empty list for null). |
| api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/ListProjectRolesCmd.java | Adds explicit project existence validation and avoids the per-role project lookup that caused the NPE. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 17630 |
|
@Tonitzpp can you check the build failure. |
|
@blueorangutan package |
|
@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17749 |
| if (projectId == null || projectId < 1L || projectDao.findById(projectId) == null) { | ||
| logger.warn("Invalid project ID provided"); | ||
| return null; | ||
| if (projectId == null) { |
There was a problem hiding this comment.
if projectid=-1, does it work before/after this change ?
There was a problem hiding this comment.
Previously, the API returned an NPE with projectid = -1 because here it returns null, and in the calling method, it tries to iterate through this null object. Now it doesn't return the NPE because an empty list will be returned in projRoleDao.findAllRoles; since there's no need to query the database, I'll change it to keep the if statement the same and return an empty list directly.
|
@Tonitzpp |
63f0803 to
f1e0864
Compare
Description
Currently, when using the
listProjectRolesAPI, passing theprojectidparameter of a removed project results in an NPE. This PR changes this behavior to return the messageFailed to find project by IDinstead.Types of changes
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
Before the changes
After the changes
How Has This Been Tested?
To perform the tests, a test project was created along with a project role. The project was deleted and the
listProjectRolesAPI was called passing the ID of the project role. This showed the new message.