[ 
https://issues.apache.org/jira/browse/GEODE-10533?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jinwoo Hwang updated GEODE-10533:
---------------------------------
    Description: 
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. Work Breakdown
h3. Phase 1: String Utilities (10 warnings, 4-6 hours)
 * Micrometer StringUtils (3 warnings) - 1-2 hours
 * Commons Lang StringUtils (7 warnings) - 3-4 hours

h3. Phase 2: Reflection APIs (7 warnings, 4-6 hours)
 * Class.newInstance() (4 warnings) - 2-3 hours (exception handling)
 * Proxy.getProxyClass() (3 warnings) - 2-3 hours

h3. Phase 3: Geode APIs (1 warning, 2-3 hours)
 * IndexType (1 warning) - 2-3 hours (research + fix)

h3. Phase 4: Type Safety (5 warnings, 2-3 hours)
 * Unchecked Stream operations (5 warnings) - 2-3 hours

*Total Estimated Effort:* 12-18 hours
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. Estimated Effort

*Story Points:* 8
*Time Estimate:* 12-18 hours
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()"

h2. Notes
 * Consider creating utility methods for commonly used string operations to 
centralize replacement logic
 * For reflection APIs, ensure proper exception handling is added for new 
checked exceptions
 * Type safety improvements may reveal additional issues that should be 
addressed
 * IndexType deprecation may require coordination with Geode core team for 
proper replacement

> 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: Jinwoo Hwang
>            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. Work Breakdown
> h3. Phase 1: String Utilities (10 warnings, 4-6 hours)
>  * Micrometer StringUtils (3 warnings) - 1-2 hours
>  * Commons Lang StringUtils (7 warnings) - 3-4 hours
> h3. Phase 2: Reflection APIs (7 warnings, 4-6 hours)
>  * Class.newInstance() (4 warnings) - 2-3 hours (exception handling)
>  * Proxy.getProxyClass() (3 warnings) - 2-3 hours
> h3. Phase 3: Geode APIs (1 warning, 2-3 hours)
>  * IndexType (1 warning) - 2-3 hours (research + fix)
> h3. Phase 4: Type Safety (5 warnings, 2-3 hours)
>  * Unchecked Stream operations (5 warnings) - 2-3 hours
> *Total Estimated Effort:* 12-18 hours
> 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. Estimated Effort
> *Story Points:* 8
> *Time Estimate:* 12-18 hours
> 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()"
> h2. Notes
>  * Consider creating utility methods for commonly used string operations to 
> centralize replacement logic
>  * For reflection APIs, ensure proper exception handling is added for new 
> checked exceptions
>  * Type safety improvements may reveal additional issues that should be 
> addressed
>  * IndexType deprecation may require coordination with Geode core team for 
> proper replacement



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to