refactor: migrate plugins/hypervisors/kvm module to JDK 21 APIs#3
refactor: migrate plugins/hypervisors/kvm module to JDK 21 APIs#3devin-ai-integration[bot] wants to merge 3 commits into
Conversation
- 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>
| boolean success = true; | ||
| try { | ||
| final URL url = new URL(sb.toString()); | ||
| final URL url = URI.create(sb.toString()).toURL(); |
There was a problem hiding this comment.
🔴 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
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).
…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>

Description
This PR migrates deprecated Java API usages in the
plugins/hypervisors/kvmmodule 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:
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)new URL(String)→URI.create(String).toURL()— TheURL(String)constructor was deprecated in JDK 20. Updated in:LibvirtConsoleProxyLoadCommandWrapper.executeProxyLoadScan()Exception handling updates —
getDeclaredConstructor().newInstance()can throwNoSuchMethodExceptionandInvocationTargetExceptionin addition toInstantiationException/IllegalAccessException. Catch blocks updated accordingly.IllegalArgumentExceptioncatch forURI.create()—URI.create()throws uncheckedIllegalArgumentExceptionfor malformed input (whereas the oldnew URL()threw checkedMalformedURLException). Added explicit catch block inLibvirtConsoleProxyLoadCommandWrapperto preserve graceful error handling.cloud-api:jar:testsartifact); CI validation is needed.Human review checklist
IllegalArgumentExceptioncatch inLibvirtConsoleProxyLoadCommandWrappercovers all failure modes fromURI.create().toURL()— confirm no other unchecked exceptions can escapeInvocationTargetExceptionimport placement inLibvirtComputingResource.javapasses any import-order checkstyle rules (it sits betweenjava.util.regexandjava.util.streamblocks)Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
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/kvmmodule 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