Skip to content

api,server: prevent npe on reset pass for expunged vm#13480

Open
shwstppr wants to merge 1 commit into
apache:4.20from
shapeblue:fix-npe-resetvm
Open

api,server: prevent npe on reset pass for expunged vm#13480
shwstppr wants to merge 1 commit into
apache:4.20from
shapeblue:fix-npe-resetvm

Conversation

@shwstppr

Copy link
Copy Markdown
Contributor

Description

Fixes NPE observed when calling resetPasswordForVirtualMachine API for an expunged VM.

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 or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Before:

(localcloud) 🐱 > reset passwordforvirtualmachine id=6aa8552f-a0ca-4520-9359-c26e06c22e4c
{
  "account": "admin1",
  "accountid": "7ef3edd8-b4ca-46b4-97d0-e7bebeb8704d",
  "cmd": "org.apache.cloudstack.api.command.admin.vm.ResetVMPasswordCmdByAdmin",
  "completed": "2026-06-24T05:01:50+0000",
  "created": "2026-06-24T05:01:30+0000",
  "domainid": "cc89a62c-6a12-11f1-bcb1-525400491d42",
  "domainpath": "ROOT",
  "jobid": "6725d884-236b-4482-b96b-964a54b6b5ea",
  "jobinstanceid": "6aa8552f-a0ca-4520-9359-c26e06c22e4c",
  "jobinstancetype": "VirtualMachine",
  "jobprocstatus": 0,
  "jobresult": {
    "errorcode": 530,
    "errortext": "Cannot invoke \"com.cloud.uservm.UserVm.getUuid()\" because \"vm\" is null"
  },
  "jobresultcode": 530,
  "jobresulttype": "object",
  "jobstatus": 2,
  "userid": "7c01a5fa-8d06-402a-8932-e6673470ac6b"
}
2026-06-24 05:01:50,231 ERROR [c.c.a.ApiAsyncJobDispatcher] (API-Job-Executor-6:[ctx-463637d6, job-16856]) (logid:6725d884) Unexpected exception while executing org.apache.cloudstack.api.command.admin.vm.ResetVMPasswordCmdByAdmin java.lang.NullPointerException: Cannot invoke "com.cloud.uservm.UserVm.getUuid()" because "vm" is null
	at org.apache.cloudstack.api.command.user.vm.ResetVMPasswordCmd.execute(ResetVMPasswordCmd.java:123)
	at com.cloud.api.ApiDispatcher.dispatch(ApiDispatcher.java:173)
	at com.cloud.api.ApiAsyncJobDispatcher.runJob(ApiAsyncJobDispatcher.java:110)
	at org.apache.cloudstack.framework.jobs.impl.AsyncJobManagerImpl$5.runInContext(AsyncJobManagerImpl.java:649)
	at org.apache.cloudstack.managed.context.ManagedContextRunnable$1.run(ManagedContextRunnable.java:49)
	at org.apache.cloudstack.managed.context.impl.DefaultManagedContext$1.call(DefaultManagedContext.java:56)
	at org.apache.cloudstack.managed.context.impl.DefaultManagedContext.callWithContext(DefaultManagedContext.java:103)
	at org.apache.cloudstack.managed.context.impl.DefaultManagedContext.runWithContext(DefaultManagedContext.java:53)
	at org.apache.cloudstack.managed.context.ManagedContextRunnable.run(ManagedContextRunnable.java:46)
	at org.apache.cloudstack.framework.jobs.impl.AsyncJobManagerImpl$5.run(AsyncJobManagerImpl.java:597)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

After:

(localcloud) 🐱 > reset passwordforvirtualmachine id=6aa8552f-a0ca-4520-9359-c26e06c22e4c
{
  "account": "admin1",
  "accountid": "7ef3edd8-b4ca-46b4-97d0-e7bebeb8704d",
  "cmd": "org.apache.cloudstack.api.command.admin.vm.ResetVMPasswordCmdByAdmin",
  "completed": "2026-06-24T05:17:43+0000",
  "created": "2026-06-24T05:17:43+0000",
  "domainid": "cc89a62c-6a12-11f1-bcb1-525400491d42",
  "domainpath": "ROOT",
  "jobid": "eeb141fa-93f2-49b5-9af7-3aed32f5184e",
  "jobinstanceid": "6aa8552f-a0ca-4520-9359-c26e06c22e4c",
  "jobinstancetype": "VirtualMachine",
  "jobprocstatus": 0,
  "jobresult": {
    "errorcode": 431,
    "errortext": "unable to find an Instance with id 5"
  },
  "jobresultcode": 431,
  "jobresulttype": "object",
  "jobstatus": 2,
  "userid": "7c01a5fa-8d06-402a-8932-e6673470ac6b"
}
🙈 Error: async API failed for job eeb141fa-93f2-49b5-9af7-3aed32f5184e

How did you try to break this feature and the system with this change?

Fixes NPE observed when calling resetPasswordForVirtualMachine API for
an expunged VM.

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
@shwstppr shwstppr marked this pull request as ready for review June 24, 2026 05:22
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.25%. Comparing base (2eb9820) to head (50f7828).

Files with missing lines Patch % Lines
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java 0.00% 7 Missing ⚠️
...dstack/api/command/user/vm/ResetVMPasswordCmd.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #13480      +/-   ##
============================================
- Coverage     16.26%   16.25%   -0.01%     
+ Complexity    13436    13434       -2     
============================================
  Files          5667     5667              
  Lines        500676   500676              
  Branches      60799    60799              
============================================
- Hits          81412    81402      -10     
- Misses       410157   410174      +17     
+ Partials       9107     9100       -7     
Flag Coverage Δ
uitests 4.14% <ø> (ø)
unittests 17.11% <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.

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

clgtm

@DaanHoogland DaanHoogland added this to the 4.20.4 milestone Jun 24, 2026
@shwstppr

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@shwstppr 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 18360

Sign up for free to 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.

3 participants