Skip to content

NPE correction when informing removed project in the listProjectRoles - #13022

Open
Tonitzpp wants to merge 2 commits into
apache:4.22from
scclouds:npe-in-listprojects
Open

NPE correction when informing removed project in the listProjectRoles#13022
Tonitzpp wants to merge 2 commits into
apache:4.22from
scclouds:npe-in-listprojects

Conversation

@Tonitzpp

Copy link
Copy Markdown
Contributor

Description

Currently, when using the listProjectRoles API, passing the projectid parameter of a removed project results in an NPE. This PR changes this behavior to return the message Failed to find project by ID instead.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

Before the changesimage
After the changesimage

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 listProjectRoles API was called passing the ID of the project role. This showed the new message.

@codecov

codecovBot commented Apr 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.67%. Comparing base (a289bb0) to head (db353f1).
⚠️ Report is 82 commits behind head on 4.22.

Files with missing linesPatch %Lines
...command/admin/acl/project/ListProjectRolesCmd.java0.00%3 Missing ⚠️
.../apache/cloudstack/acl/ProjectRoleManagerImpl.java0.00%2 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## 4.22 #13022 +/- ##
============================================
- Coverage 17.67% 17.67% -0.01% + Complexity 15792 15786 -6 
============================================
Files 5922 5922 Lines 533123 533125 +2 Branches 65201 65201 ============================================
- Hits 94246 94240 -6 - Misses 428236 428240 +4 - Partials 10641 10645 +4 
FlagCoverage Δ
uitests3.69% <ø> (ø)
unittests18.75% <0.00%> (-0.01%)⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.findProjectRoles to return an empty list when projectId is null (instead of returning null).
  • Add explicit project existence validation in ListProjectRolesCmd.execute() and throw InvalidParameterValueException when the project cannot be found.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

FileDescription
server/src/main/java/org/apache/cloudstack/acl/ProjectRoleManagerImpl.javaPrevents null list returns from findProjectRoles when projectId is null.
api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/ListProjectRolesCmd.javaValidates 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.

@TonitzppTonitzpp changed the title NPE correction when informing removed project in the 'listProjectRoles'NPE correction when informing removed project in the listProjectRolesApr 17, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 projectId in ListProjectRolesCmd.execute() and throw an InvalidParameterValueException when the project can’t be found.
  • Avoid per-role project lookup when building ProjectRoleResponse by passing the project UUID through the response setup method.
  • Adjust ProjectRoleManagerImpl.findProjectRoles() to return an empty list when projectId is null (instead of returning null).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

FileDescription
server/src/main/java/org/apache/cloudstack/acl/ProjectRoleManagerImpl.javaReturns 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.javaAdds 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.

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@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.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 an InvalidParameterValueException when the project can’t be found.
  • Avoid calling _projectService.getProject(...).getUuid() per role by reusing the resolved project UUID.
  • Adjust ProjectRoleManagerImpl.findProjectRoles to return an empty list for null project IDs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

FileDescription
server/src/main/java/org/apache/cloudstack/acl/ProjectRoleManagerImpl.javaChanges 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.javaAdds 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.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 17630

@sureshanaparti

Copy link
Copy Markdown
Contributor

@Tonitzpp can you check the build failure.

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@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.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17749

Comment threadserver/src/main/java/org/apache/cloudstack/acl/ProjectRoleManagerImpl.java Outdated
@weizhouapache

Copy link
Copy Markdown
Member

@Tonitzpp
does the issue exist in main branch only ?
if it exists in older branches, can you re-target to 4.20/4.22 ?

@Tonitzpp
Tonitzppforce-pushed the npe-in-listprojects branch from 63f0803 to f1e0864CompareMay 13, 2026 13:03
@Tonitzpp
Tonitzpp changed the base branch from main to 4.22May 13, 2026 13:03
@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17929

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian Build Failed (tid-16145)

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-16157)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 60370 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr13022-t16157-kvm-ol8.zip
Smoke tests completed. 146 look OK, 3 have errors, 0 did not run
Only failed and skipped tests results shown below:

TestResultTime (s)Test File
test_02_1_create_iso_with_checksum_sha256_negativeError66.91test_iso.py
test_02_create_iso_with_checksum_sha256Error66.98test_iso.py
test_03_create_iso_with_checksum_md5Error66.75test_iso.py
test_04_create_iso_with_no_checksumError66.75test_iso.py
test_04_extract_IsoError124.45test_iso.py
ContextSuite context=TestListIdsParams>:teardownError1.19test_list_ids_parameter.py
test_01_vpn_usageError1.15test_usage.py

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@Tonitzpp@DaanHoogland@blueorangutan@sureshanaparti@weizhouapache@vladimirpetrov