Skip to content

Upgrade Guava library to version 32.0.0-jre in CDAP Runtime module#16126

Open
AbhishekKumar9984 wants to merge 1 commit into
cdapio:cs_guava_upgradefrom
cloudsufi:preview-runner-cloudsufi-guava-upgrade
Open

Upgrade Guava library to version 32.0.0-jre in CDAP Runtime module#16126
AbhishekKumar9984 wants to merge 1 commit into
cdapio:cs_guava_upgradefrom
cloudsufi:preview-runner-cloudsufi-guava-upgrade

Conversation

@AbhishekKumar9984
Copy link
Copy Markdown

Updated the Guava dependency version in pom.xml to 32.0.0-jre.
Addressed compatibility issues with the upgraded Guava version.

Copy link
Copy Markdown

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

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 contains a large number of changes primarily focused on replacing deprecated Guava methods (like Throwables.propagate, Closeables.closeQuietly, and Stopwatch.elapsedMillis) with standard Java equivalents or safer alternatives, and updating service lifecycle management from startAndWait/stopAndWait to startAsync().awaitRunning()/stopAsync().awaitTerminated(). While these changes modernize the codebase, several issues were identified regarding performance regressions, potential compatibility issues with newer Java versions, and incorrect exception handling patterns.

Comment on lines +376 to +377
e -> ((ApplicationFilter.ArtifactIdFilter) filter).test(
e.getValue().getSpec().getArtifactId()));
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 removal of the getArtifactId() method in AppScanEntry and the change to use e.getValue().getSpec().getArtifactId() here introduces a significant performance regression. e.getValue() triggers a full JSON deserialization of the ApplicationMeta object, which can be quite large and expensive. The previous implementation used a streaming JsonReader to efficiently extract only the required artifactId field without deserializing the entire specification. This optimization should be preserved to maintain performance when scanning applications with artifact filters.

Comment on lines 37 to 39
private static final Gson GSON = new GsonBuilder().registerTypeAdapter(Schema.class,
new SchemaTypeAdapter())
// Starting java 9, some java internal modules are private and cannot be used by current
// version of gson. https://cdap.atlassian.net/browse/CDAP-21212
.setExclusionStrategies(new com.google.gson.ExclusionStrategy() {
@Override
public boolean shouldSkipField(com.google.gson.FieldAttributes f) {
return false;
}

@Override
public boolean shouldSkipClass(Class<?> clazz) {
String name = clazz.getName();
return name.startsWith("java.lang.module")
|| name.startsWith("jdk.internal")
|| name.startsWith("sun.");
}
})
.registerTypeAdapter(StructuredRecord.class, new PreviewJsonSerializer()).create();
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

The removal of the ExclusionStrategy for GSON may cause issues when running on Java 9 or later. This strategy was specifically implemented to avoid reflection-based access to internal JDK modules (like java.lang.module or jdk.internal), which is restricted in newer Java versions and can lead to InaccessibleObjectException. The original code referenced CDAP-21212 as the reason for this inclusion. Please verify if this exclusion is still necessary for compatibility.

String line;
try (InputStreamReader reader = new InputStreamReader(Locations.newInputSupplier(resultLocation).getInput(),
Charsets.UTF_8)) {
line = CharStreams.readLines(reader).stream().findFirst().orElse(null);
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

CharStreams.readLines(reader) reads the entire content of the file into a list in memory. Since only the first line is needed for verification, this is inefficient if the output file is large. It is better to use a BufferedReader and read only the first line.

Suggested change
line = CharStreams.readLines(reader).stream().findFirst().orElse(null);
line = new BufferedReader(reader).readLine();

}

@Test
@Test
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

The removal of testScanApplicationsWithArtifactFilter and related tests significantly reduces the test coverage for application scanning logic. These tests should be retained to ensure that filtering by artifact still works correctly after the implementation changes, especially given the performance-related changes in the store implementation.

Comment on lines 160 to +161
LOG.error(t.getMessage(), t);
throw Throwables.propagate(t);
throw new RuntimeException(t);
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

Replacing Throwables.propagate(t) with new RuntimeException(t) when catching Throwable is problematic. Guava's propagate method would throw Error and RuntimeException types directly, whereas the new code wraps them in a RuntimeException. This changes the exception propagation behavior and can lead to unnecessary exception nesting or incorrect handling of fatal errors. The recommended replacement is to use Throwables.throwIfUnchecked(t) before wrapping.

      LOG.error(t.getMessage(), t);
      Throwables.throwIfUnchecked(t);
      throw new RuntimeException(t);

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant