Skip to content

Cs guava upgrade - #16190

Open
sahusanket wants to merge 15 commits into
developfrom
cs_guava_upgrade
Open

Cs guava upgrade#16190
sahusanket wants to merge 15 commits into
developfrom
cs_guava_upgrade

Conversation

@sahusanket

Copy link
Copy Markdown
Contributor

No description provided.

vanshikaagupta22 and others added 15 commits May 6, 2026 03:51
- Updated the Guava dependency version in `pom.xml` to 32.0.0-jre.
- Ensured compatibility with the upgraded Guava version.

fixes

commnet fixes

fixes comments
fixes

comments resolved

fixes new
fixes haddop fixes

fixes
Optimize AppScanEntry artifact filtering to avoid full JSON deserialization

Restore GSON ExclusionStrategy in DefaultDataTracer to avoid reflection access errors on Java 9+

Restore testScanApplicationsWithArtifactFilter and testScanApplicationsWithArtifactFilterCoverage in AppMetadataStoreTest.java

Clean up try-catch block formatting in TwillAppLifecycleEventHandler.java

Clean up formatting and add comments inside empty catch block in AbstractProgramRuntimeService.java

Clean up try-catch formatting and add catch block comments in TransactionHttpHandler.java

Clean up formatting and add comments inside catch blocks in ArtifactClassLoaderFactory.java

Use simple imports for java.io stream types in MapReduceRuntimeService.java

Clean up try-catch block formatting in DefaultRuntimeJob.java

Clean up try-catch formatting in PluginInstantiator.java

Clean up try-catch formatting in DefaultProgramWorkflowRunner.java

Use simple imports for java.io streams and java.nio Files in LocalizationUtils.java

Clean up try-catch block formatting in HubPackage.java

Clean up InterruptedException catch block formatting in OperationalStatsService.java

Use Guava Files.copy instead of java.nio.file.Files.copy in HttpHandlerGeneratorTest.java

Clean up try-catch block formatting in OperationLifecycleManagerTest.java
Simplify TxMetricsCollector start/stop methods using direct calls to delegate instead of reflection
fixes
…upgrade

Upgrade Guava library to version 32.0.0-jre in CDAP common module
Upgrade Guava library to version 32.0.0-jre-router pod
Upgrade Guava library to version 32.0.0-jre-preview pod
…grade

Upgrade Guava library to version 32.0.0-jre in CDAP Watchdog module
Upgrade Guava library to version 32.0.0-jre in cdap
…a-upgrade

Upgrade Guava library to version 32.0.0-jre-userInterface pod
…va-upgrade

Upgrade Guava library to version 32.0.0-jre in CDAP Runtime module
@sahusanket sahusanket added the build Triggers github actions build label Aug 6, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request performs a major cleanup of deprecated Guava and Twill APIs across the codebase, notably replacing synchronous service lifecycle methods (such as startAndWait and stopAndWait) with their asynchronous counterparts (startAsync and stopAsync), replacing Throwables.propagate with standard exceptions, and migrating to MoreObjects and modern CharMatcher and Stopwatch APIs. Additionally, the custom GuavaClassRewriter is removed, and stub suppliers are introduced to maintain compatibility. The review feedback highlights critical issues and improvement opportunities: first, in Services.java, retrieving methods via reflection using service.getClass() instead of Service.class will fail with an IllegalAccessException if the concrete service class is non-public; second, in AppMetadataStore.java, removing IllegalStateException from the catch block during JSON parsing exposes the scan operation to unhandled runtime exceptions from malformed metadata; and third, several files, including LocalizationUtils.java and MapReduceRuntimeService.java, can be simplified by using standard Java NIO Files.copy or native Location stream methods directly instead of deprecated custom supplier wrappers.

Comment on lines +95 to +99
service.getClass().getMethod("startAsync").invoke(service);
service.getClass().getMethod("awaitRunning").invoke(service);
} catch (NoSuchMethodException e) {
// Guava 13
Object future = service.getClass().getMethod("start").invoke(service);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using service.getClass().getMethod(...) to retrieve methods via reflection will throw an IllegalAccessException if the concrete class of the Service is non-public (such as package-private or anonymous classes), even if the methods themselves are public. Since Service is a public interface, you should retrieve the methods from Service.class instead of service.getClass().

Suggested change
service.getClass().getMethod("startAsync").invoke(service);
service.getClass().getMethod("awaitRunning").invoke(service);
} catch (NoSuchMethodException e) {
// Guava 13
Object future = service.getClass().getMethod("start").invoke(service);
Service.class.getMethod("startAsync").invoke(service);
Service.class.getMethod("awaitRunning").invoke(service);
} catch (NoSuchMethodException e) {
// Guava 13
Object future = Service.class.getMethod("start").invoke(service);

Comment on lines +120 to +124
service.getClass().getMethod("stopAsync").invoke(service);
service.getClass().getMethod("awaitTerminated").invoke(service);
} catch (NoSuchMethodException e) {
// Guava 13
Object future = service.getClass().getMethod("stop").invoke(service);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using service.getClass().getMethod(...) to retrieve methods via reflection will throw an IllegalAccessException if the concrete class of the Service is non-public (such as package-private or anonymous classes), even if the methods themselves are public. Since Service is a public interface, you should retrieve the methods from Service.class instead of service.getClass().

Suggested change
service.getClass().getMethod("stopAsync").invoke(service);
service.getClass().getMethod("awaitTerminated").invoke(service);
} catch (NoSuchMethodException e) {
// Guava 13
Object future = service.getClass().getMethod("stop").invoke(service);
Service.class.getMethod("stopAsync").invoke(service);
Service.class.getMethod("awaitTerminated").invoke(service);
} catch (NoSuchMethodException e) {
// Guava 13
Object future = Service.class.getMethod("stop").invoke(service);

Comment on lines +3222 to 3224
} catch (IOException e) {
LOG.warn("Failed to extract artifact id from raw application metadata", e);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The JsonReader operations (such as beginObject, peek, nextName, and skipValue) as well as GSON.fromJson can throw IllegalStateException or JsonSyntaxException (which are RuntimeExceptions) if the JSON metadata is malformed or has an unexpected structure (e.g., if spec is a string instead of an object). Since you removed IllegalStateException from the catch block, any such malformed metadata in the database will cause the entire scan operation to fail with an unhandled exception. Please catch Exception or IOException | RuntimeException to safely handle and log these parsing errors.

Suggested change
} catch (IOException e) {
LOG.warn("Failed to extract artifact id from raw application metadata", e);
}
} catch (Exception e) {
LOG.warn("Failed to extract artifact id from raw application metadata", e);
}

Comment on lines +92 to +95
try (InputStream in = Resources.asByteSource(url).openStream();
OutputStream out = new FileOutputStream(tempFile)) {
com.google.common.io.ByteStreams.copy(in, out);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Instead of manually opening a FileOutputStream and using ByteStreams.copy, you can use the standard Java NIO Files.copy method to copy the InputStream directly to the target path. This is cleaner, more concise, and utilizes optimized platform-specific copy operations.

    try (InputStream in = Resources.asByteSource(url).openStream()) {
      Files.copy(in, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    }

Comment on lines +1015 to +1018
try (InputStream in = new FileInputStream(file);
OutputStream out = Locations.newOutputSupplier(targetLocation).getOutput()) {
ByteStreams.copy(in, out);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Since Location provides a direct getOutputStream() method, you can use it directly instead of wrapping it with Locations.newOutputSupplier. This simplifies the code and avoids using the custom/deprecated supplier wrapper.

Suggested change
try (InputStream in = new FileInputStream(file);
OutputStream out = Locations.newOutputSupplier(targetLocation).getOutput()) {
ByteStreams.copy(in, out);
}
try (InputStream in = new FileInputStream(file);
OutputStream out = targetLocation.getOutputStream()) {
ByteStreams.copy(in, out);
}

Comment on lines +1030 to +1033
try (InputStream in = Locations.newInputSupplier(programJarLocation).getInput();
OutputStream out = Locations.newOutputSupplier(programJarCopy).getOutput()) {
ByteStreams.copy(in, out);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Since both programJarLocation and programJarCopy are Location objects, you can use their native getInputStream() and getOutputStream() methods directly instead of wrapping them with Locations.newInputSupplier and Locations.newOutputSupplier. This simplifies the code and avoids using the custom/deprecated supplier wrappers.

Suggested change
try (InputStream in = Locations.newInputSupplier(programJarLocation).getInput();
OutputStream out = Locations.newOutputSupplier(programJarCopy).getOutput()) {
ByteStreams.copy(in, out);
}
try (InputStream in = programJarLocation.getInputStream();
OutputStream out = programJarCopy.getOutputStream()) {
ByteStreams.copy(in, out);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Triggers github actions build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants