refactor: migrate plugins/hypervisors/kvm module to JDK 21 APIs by devin-ai-integration[bot] · Pull Request #3 · hitomimimi/cloudstack · GitHub
Skip to content

refactor: migrate plugins/hypervisors/kvm module to JDK 21 APIs#3

Open
devin-ai-integration[bot] wants to merge 3 commits into
demo/java-21-foundationfrom
devin/1778297371-kvm-jdk21-migration
Open

refactor: migrate plugins/hypervisors/kvm module to JDK 21 APIs#3
devin-ai-integration[bot] wants to merge 3 commits into
demo/java-21-foundationfrom
devin/1778297371-kvm-jdk21-migration

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented May 9, 2026

Copy link
Copy Markdown

Description

This PR migrates deprecated Java API usages in the plugins/hypervisors/kvm module to JDK 21-compatible alternatives. This is a follow-up to the JDK 21 foundation work on the base branch (demo/java-21-foundation), scoped specifically to the KVM hypervisor plugin.

Changes:

  1. Class.newInstance()getDeclaredConstructor().newInstance()Class.newInstance() has been deprecated since JDK 9 and is flagged for removal. Updated in:

    • LibvirtComputingResource.getVifDriverClass() (VIF driver instantiation)
    • LibvirtVMDef.MetadataDef.getMetadataNode() (metadata node instantiation)
    • LibvirtVifDriverTest.setUp() (test setup)
  2. new URL(String)URI.create(String).toURL() — The URL(String) constructor was deprecated in JDK 20. Updated in:

    • LibvirtConsoleProxyLoadCommandWrapper.executeProxyLoadScan()
  3. Exception handling updatesgetDeclaredConstructor().newInstance() can throw NoSuchMethodException and InvocationTargetException in addition to InstantiationException/IllegalAccessException. Catch blocks updated accordingly.

  4. IllegalArgumentException catch for URI.create()URI.create() throws unchecked IllegalArgumentException for malformed input (whereas the old new URL() threw checked MalformedURLException). Added explicit catch block in LibvirtConsoleProxyLoadCommandWrapper to preserve graceful error handling.

⚠️ Reviewer notes:

  • Local Maven compilation could not be verified end-to-end due to a pre-existing dependency resolution issue (cloud-api:jar:tests artifact); CI validation is needed.

Human review checklist

  • Verify that the IllegalArgumentException catch in LibvirtConsoleProxyLoadCommandWrapper covers all failure modes from URI.create().toURL() — confirm no other unchecked exceptions can escape
  • Confirm InvocationTargetException import placement in LibvirtComputingResource.java passes any import-order checkstyle rules (it sits between java.util.regex and java.util.stream blocks)
  • Validate via CI that the reflection-based instantiation changes don't break any existing tests

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

How Has This Been Tested?

Pre-commit hooks passed. Full Maven compilation could not be completed locally due to a pre-existing dependency resolution issue unrelated to this change. CI should confirm compilation and test correctness.

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

Grepped the entire plugins/hypervisors/kvm module for all known JDK 21 deprecations (Class.newInstance(), new URL(String), finalize(), SecurityManager, sun.misc.*, javax.xml.bind, wrapper constructors, AccessController, etc.) to ensure comprehensive coverage. Only the patterns addressed in this PR were found.

Link to Devin session: https://app.devin.ai/sessions/fff0b28c11d7403681d7b4f57d2cf478
Requested by: @hitomimimi


Open in Devin Review

- Replace deprecated Class.newInstance() with getDeclaredConstructor().newInstance()
  in LibvirtComputingResource, LibvirtVMDef, and LibvirtVifDriverTest
- Replace deprecated new URL(String) with URI.create(String).toURL()
  in LibvirtConsoleProxyLoadCommandWrapper
- Update exception handling for NoSuchMethodException and InvocationTargetException

Co-Authored-By: hitomi.sawamura@gmail.com <hitomi.sawamura@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

boolean success = true;
try {
final URL url = new URL(sb.toString());
final URL url = URI.create(sb.toString()).toURL();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🔴 URI.create() throws uncaught IllegalArgumentException instead of previously-caught IOException

The migration from new URL(sb.toString()) to URI.create(sb.toString()).toURL() changes the exception behavior. URI.create() throws IllegalArgumentException (an unchecked exception) when the string is not a valid URI, whereas the original new URL() threw MalformedURLException (extends IOException) which was caught by the existing catch (final IOException e) block at line 70. If proxyManagementIp contains characters invalid for a URI, the uncaught IllegalArgumentException will now propagate up the call stack instead of being gracefully handled by returning a ConsoleProxyLoadAnswer with success = false.

Suggested change
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in bc238e7 — added a catch (final IllegalArgumentException e) block to preserve the same graceful error handling behavior as the original MalformedURLException (which extended IOException).

devin-ai-integration Bot and others added 2 commits May 9, 2026 03:43
…LoadCommandWrapper

Address Devin Review feedback: URI.create() throws unchecked
IllegalArgumentException instead of the previously-caught IOException
from new URL(). Add catch block to preserve graceful error handling.

Co-Authored-By: hitomi.sawamura@gmail.com <hitomi.sawamura@gmail.com>
Replace java.lang.reflect.InvocationTargetException FQN references with
a proper import statement in both LibvirtComputingResource and LibvirtVMDef.

Co-Authored-By: hitomi.sawamura@gmail.com <hitomi.sawamura@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant