[
https://issues.apache.org/jira/browse/GEODE-10533?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jinwoo Hwang reassigned GEODE-10533:
------------------------------------
Assignee: ventsislav (was: Jinwoo Hwang)
> Fix Deprecated APIs in geode-gfsh Module
> ----------------------------------------
>
> Key: GEODE-10533
> URL: https://issues.apache.org/jira/browse/GEODE-10533
> Project: Geode
> Issue Type: Improvement
> Reporter: Jinwoo Hwang
> Assignee: ventsislav
> Priority: Major
>
> h2. Summary
> Fix 18 deprecated API warnings and 5 unchecked type safety warnings in the
> {{geode-gfsh}} module. This excludes the 3 {{[removal]}} warnings for
> {{getRawStatusCode()}} which are handled in a separate ticket.
> h2. Description
> The {{geode-gfsh}} module contains 18 deprecation warnings and 5 unchecked
> type safety warnings across multiple packages and files. These warnings do
> not block Java or Spring upgrades but should be addressed to maintain code
> quality and prepare for future library migrations.
> *Module:* {{geode-gfsh}}
> *Total Warnings:* 18 [deprecation] + 5 [unchecked] = 23 warnings
> *Priority:* MEDIUM - Technical debt cleanup
> h2. Affected Files and Packages
> h3. 1. Micrometer StringUtils (3 warnings)
> *Package:* {{org.apache.geode.management.internal.cli.commands.lifecycle}}
> *File:* {{StopServerCommand.java:17}}
> *Count:* 3 warnings
> *Deprecated API:*
> {code:java}
> io.micrometer.core.instrument.util.StringUtils
> {code}
> *Issue:* Internal utility class not meant for public use
> *Replacement:* {{org.springframework.util.StringUtils}} or Java standard
> library methods
> h3. 2. Apache Commons Lang StringUtils (7 warnings)
> *Package:* {{org.apache.geode.management.internal.cli.commands}}
> *Files:*
> * {{ConnectCommand.java:120}} (1 warning)
> * {{QueryCommand.java:84, 85}} (2 warnings)
> * {{CreateIndexCommand.java:169}} (1 warning)
> *Package:* {{org.apache.geode.management.internal.cli.domain}}
> *Files:*
> * {{FixedPartitionAttributesInfo.java:40}} (1 warning)
> * {{RegionAttributesInfo.java:367}} (1 warning)
> * {{PartitionAttributesInfo.java:155, 157}} (2 warnings)
> *Deprecated APIs and Replacements:*
> *API 1: StringUtils.startsWith()*
> {code:java}
> // Deprecated
> org.apache.commons.lang3.StringUtils.startsWith(CharSequence str,
> CharSequence prefix)
> // Replace with
> String.startsWith(String prefix)
> {code}
> *API 2: StringUtils.containsIgnoreCase()*
> {code:java}
> // Deprecated
> org.apache.commons.lang3.StringUtils.containsIgnoreCase(CharSequence str,
> CharSequence searchStr)
> // Replace with
> str.toLowerCase().contains(searchStr.toLowerCase())
> // or use String.toLowerCase(Locale.ROOT) for locale-independence
> {code}
> *API 3: StringUtils.equals()*
> {code:java}
> // Deprecated
> org.apache.commons.lang3.StringUtils.equals(CharSequence cs1, CharSequence
> cs2)
> // Replace with
> java.util.Objects.equals(Object a, Object b)
> {code}
> *API 4: StringUtils.removeStart()*
> {code:java}
> // Deprecated
> org.apache.commons.lang3.StringUtils.removeStart(String str, String remove)
> // Replace with
> str.startsWith(prefix) ? str.substring(prefix.length()) : str
> {code}
> h3. 3. Geode Query API - IndexType (1 warning)
> *Package:* {{org.apache.geode.management.internal.cli}}
> *File:* {{GfshParser.java:708}}
> *Count:* 1 warning
> *Deprecated API:*
> {code:java}
> org.apache.geode.cache.query.IndexType
> {code}
> *Action:* Consult Geode API documentation for replacement (likely moved or
> restructured in newer Geode versions)
> h3. 4. Java Reflection - Class.newInstance() (4 warnings)
> *Package:* {{org.apache.geode.management.internal.cli.functions}}
> *Files:*
> * {{RegionFunctionArgs.java:609}} (1 warning)
> * {{CreateAsyncEventQueueFunction.java:116, 160}} (2 warnings)
> * {{UserFunctionExecution.java:113}} (1 warning)
> *Deprecated API:*
> {code:java}
> java.lang.Class.newInstance()
> {code}
> *Deprecated Since:* Java 9
> *Removal Target:* Not scheduled
> *Migration Pattern:*
> {code:java}
> // Before:
> try {
> Object instance = clazz.newInstance();
> } catch (InstantiationException | IllegalAccessException e) {
> // handle
> }
> // After:
> try {
> Object instance = clazz.getDeclaredConstructor().newInstance();
> } catch (InstantiationException | IllegalAccessException |
> InvocationTargetException | NoSuchMethodException e) {
> // handle
> }
> {code}
> *Note:* The replacement throws additional exceptions:
> {{{}InvocationTargetException{}}}, {{NoSuchMethodException}}
> h3. 5. Proxy.getProxyClass() (3 warnings)
> *Package:* {{org.apache.geode.management.internal.cli.commands}}
> *File:* (File name not specified in warning analysis)
> *Count:* 3 warnings (based on API pattern table)
> *Deprecated API:*
> {code:java}
> java.lang.reflect.Proxy.getProxyClass(ClassLoader loader, Class<?>...
> interfaces)
> {code}
> *Deprecated Since:* Java 9
> *Replacement:* {{Proxy.newProxyInstance(ClassLoader loader, Class<?>[]
> interfaces, InvocationHandler h)}}
> h3. 6. Type Safety - Unchecked Stream Operations (5 warnings)
> *Package:* {{org.apache.geode.management.internal.cli.commands}}
> *File:* {{ShowMissingDiskStoreCommand.java:87-90}}
> *Count:* 5 warnings
> *Issue:* Raw type usage with Stream API - missing generic type parameters
> *Warnings:*
> {code:java}
> Line 87: warning: [unchecked] unchecked method invocation: method flatMap in
> interface Stream
> Line 88: warning: [unchecked] unchecked call to filter(Predicate<? super T>)
> Line 89: warning: [unchecked] unchecked call to <R>map(Function<? super T,?
> extends R>)
> Line 90: warning: [unchecked] unchecked call to <R,A>collect(Collector<?
> super T,A,R>)
> Line 90: warning: [unchecked] unchecked cast
> {code}
> *Migration Pattern:*
> {code:java}
> // Before (raw type):
> Stream stream = getStream();
> List result = stream.filter(...).map(...).collect(Collectors.toList());
> // After (with generics):
> Stream<MyType> stream = getStream();
> List<MyType> result =
> stream.filter(...).map(...).collect(Collectors.toList());
> {code}
> h2. How to Verify Warnings
> *Step 1:* Enable warnings in
> {{{}build-tools/scripts/src/main/groovy/warnings.gradle{}}}:
> {code:groovy}
> tasks.withType(JavaCompile) {
> options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation' <<
> '-Xlint:removal'
> options.deprecation = true
> }
> {code}
> *Step 2:* Build and check warnings:
> {code:bash}
> ./gradlew clean :geode-gfsh:compileJava --no-build-cache 2>&1 | grep
> "warning:" | grep -v "getRawStatusCode"
> {code}
> *Step 3:* After fixing, restore original configuration:
> {code:bash}
> git checkout build-tools/scripts/src/main/groovy/warnings.gradle
> {code}
> h2. References
> * [Apache Commons Lang 3 Migration
> Guide|https://commons.apache.org/proper/commons-lang/article3_0.html]
> * [Java 9 Reflection API
> Changes|https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html#newInstance--]
> * [Proxy API
> Documentation|https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Proxy.html]
> * [Java Generics Best
> Practices|https://docs.oracle.com/javase/tutorial/java/generics/]
> h2. Acceptance Criteria
> * All 18 [deprecation] warnings resolved
> * All 5 [unchecked] warnings resolved
> * Code compiles without warnings in Java 17
> * All existing GFSH tests pass
> * No changes to public API behavior
> * Exception handling properly updated for reflection API changes
> * Type safety improved with proper generics
> h2. Testing Strategy
> * Unit tests: Verify all modified methods maintain existing behavior
> * Integration tests: Run full GFSH command suite
> * Reflection tests: Verify class instantiation and proxy creation
> * String operations: Test null handling, edge cases
> * Stream operations: Verify type safety and collection results
> h2. Impact
> *Risk:* MEDIUM - Does not block Java or Spring upgrades, but improves code
> quality and prepares for future library migrations
> *Scope:* 9 files across 4 packages
> *Related Work:* Part of Java 17 warning cleanup effort (36 total warnings
> across 6 modules)
> *Reusability:* 72% of these warnings follow repeatable patterns (e.g.,
> StringUtils methods, reflection APIs)
> h2. Dependencies
> * This ticket excludes the 3 {{[removal]}} warnings for
> {{ClientHttpResponse.getRawStatusCode()}}
> * Those warnings are handled in separate ticket: "Replace getRawStatusCode()
> with getStatusCode().value()"
--
This message was sent by Atlassian Jira
(v8.20.10#820010)