{{ message }}
refactor: migrate server module to JDK 21 - replace deprecated APIs#2
Open
devin-ai-integration[bot] wants to merge 3 commits into
Open
Conversation
- Replace Class.newInstance() with Class.getDeclaredConstructor().newInstance() in ApiAsyncJobDispatcher, ApiResponseHelper, APIAuthenticationManagerImpl - Replace new URL() with URI.create().toURL() in TemplateManagerImpl, VolumeApiServiceImpl, ExternalIpAddressAllocator - Replace deprecated wrapper constructors (new Long/Integer/Boolean/Double) with valueOf() factory methods across 20 files Co-Authored-By: hitomi.sawamura@gmail.com <hitomi.sawamura@gmail.com>
Author
Co-Authored-By: hitomi.sawamura@gmail.com <hitomi.sawamura@gmail.com>
…tructor().newInstance() Co-Authored-By: hitomi.sawamura@gmail.com <hitomi.sawamura@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
This PR migrates the
servermodule to JDK 21 by replacing deprecated and removed APIs across 23 source files. It builds on top of thedemo/java-21-foundationbranch which already updated the root POM (JDK version, compiler/surefire/failsafe plugins,--add-opensflags) and CI workflow.Three categories of changes:
1.
Class.newInstance()→Class.getDeclaredConstructor().newInstance()Class.newInstance()was deprecated in JDK 9 (for removal) because it bypasses checked-exception handling. Updated in:ApiAsyncJobDispatcherApiResponseHelper— also broadened catch clause fromInstantiationException | IllegalAccessExceptiontoReflectiveOperationExceptionto coverNoSuchMethodExceptionandInvocationTargetExceptionnow thrown by the new reflection path.APIAuthenticationManagerImpl— same catch clause broadening as above.2.
new URL(String)→URI.create(String).toURL()The
URLconstructors were deprecated in JDK 20. Updated in:TemplateManagerImplVolumeApiServiceImplExternalIpAddressAllocatorURI.create()throws uncheckedIllegalArgumentExceptionon malformed input, whereas the oldnew URL()threw checkedMalformedURLException. InExternalIpAddressAllocator, existingcatch (MalformedURLException)blocks will no longer catch malformed-URI errors at theURI.create()stage. The.toURL()call still throwsMalformedURLExceptionfor unknown protocols. In practice the URLs here are constructed programmatically from configuration, so this is low risk, but worth verifying.3. Deprecated wrapper constructors →
valueOf()factory methodsnew Long/Integer/Boolean/Double(...)constructors were deprecated in JDK 9 (marked for removal in JDK 16+). Replaced withLong.valueOf(...),Integer.valueOf(...),Boolean.valueOf(...),Double.valueOf(...)across 20 files. These are semantically equivalent and additionally benefit from the JVM's internal caching of common values.Test source files (
server/src/test/) were intentionally not modified in this PR to keep the scope focused.Updates since initial revision
import java.net.URLfromVolumeApiServiceImplandTemplateManagerImpl(caught by checkstyle CI). The import remains inExternalIpAddressAllocatorwhere theURLtype is still used as a local variable.catchclause inApiResponseHelper.createVlanIpRangeResponsefromInstantiationException | IllegalAccessExceptiontoReflectiveOperationExceptionto fix compilation failure —getDeclaredConstructor().newInstance()declaresNoSuchMethodExceptionandInvocationTargetExceptionas checked exceptions.Human review checklist
URI.create()exception semantics change inExternalIpAddressAllocatoris acceptable (existingcatch (MalformedURLException)won't catchIllegalArgumentExceptionfrom malformed URIs)ReflectiveOperationExceptionbroadening inAPIAuthenticationManagerImplandApiResponseHelperdoesn't silently swallow unexpected errorsLong.valueOf()/Integer.valueOf()replacements for correctness (especially aroundnullhandling — all replaced call sites pass primitives or non-null expressions)Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
How Has This Been Tested?
Changes are mechanical replacements of deprecated APIs with their recommended JDK 21 equivalents. No behavioral changes are intended (see reviewer note on
URI.create()exception semantics above). Compilation and test verification is deferred to CI on JDK 21.How did you try to break this feature and the system with this change?
server/src/main/javaviarg 'new (Long|Integer|Boolean|Double)\('Class.newInstance()usages inserver/src/main/javanew URL(usages inserver/src/main/javaURLimports removed in follow-up commit)Link to Devin session: https://app.devin.ai/sessions/2800e178a7d34c59b2c3d5d9b4083373
Requested by: @hitomimimi