Skip to content

Working guava - #16237

Open
AbhishekKumar9984 wants to merge 7 commits into
cdapio:developfrom
cloudsufi:working_guava
Open

AbhishekKumar9984 wants to merge 7 commits into
cdapio:developfrom
cloudsufi:working_guava

Conversation

@AbhishekKumar9984

Copy link
Copy Markdown

No description provided.

@google-cla

google-cla Bot commented Sep 30, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@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 refactors the codebase to migrate away from deprecated or removed Guava APIs, replacing 'Closeables.closeQuietly' with manual try-catch blocks, updating 'Service' lifecycle methods to use asynchronous start/stop patterns, and replacing 'Objects.firstNonNull' with 'MoreObjects.firstNonNull'. Feedback on these changes highlights several critical issues: potential 'NullPointerException's where null-safety was lost during the 'closeQuietly' replacements, potential 'IllegalStateException's from starting already-running shared services, and minor inefficiencies such as reading entire files into memory in tests or using 'Optional' in frequently called methods.

Comment on lines +63 to +69
try {

sshSession.close();

} catch (Exception ignored) {

}

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

If sshSession is null, calling sshSession.close() directly will throw a NullPointerException. Since the original Closeables.closeQuietly was null-safe, we should add an explicit null check before calling close().

    if (sshSession != null) {
      try {
        sshSession.close();
      } catch (Exception ignored) {
      }
    }

Comment on lines +75 to +81
try {

sshSession.close();

} catch (Exception ignored) {

}

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

If sshSession is null, calling sshSession.close() directly will throw a NullPointerException. Since the original Closeables.closeQuietly was null-safe, we should add an explicit null check before calling close().

    if (sshSession != null) {
      try {
        sshSession.close();
      } catch (Exception ignored) {
      }
    }

Comment on lines +283 to +289
try {

input.close();

} catch (Exception ignored) {

}

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

If input is null (which can happen if responseCode >= 400), calling input.close() directly will throw a NullPointerException. We should add an explicit null check before calling close().

      if (input != null) {
        try {
          input.close();
        } catch (Exception ignored) {
        }
      }

Comment on lines +328 to +332
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

Using CharStreams.readLines(reader) reads the entire file into memory just to retrieve the first line, which is highly inefficient and can cause OutOfMemoryError for larger files. We should use a BufferedReader to read only the first line.

Suggested change
String line;
try (InputStreamReader reader = new InputStreamReader(Locations.newInputSupplier(resultLocation).getInput(),
Charsets.UTF_8)) {
line = CharStreams.readLines(reader).stream().findFirst().orElse(null);
}
String line;
try (java.io.BufferedReader reader = new java.io.BufferedReader(
new InputStreamReader(Locations.newInputSupplier(resultLocation).getInput(), Charsets.UTF_8))) {
line = reader.readLine();
}

Comment on lines +149 to +150
taskContextProvider = Optional.ofNullable(taskContextProvider)
.orElseGet(taskContextProviderSupplier::get);

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

Using Optional.ofNullable(...).orElseGet(...) creates a new Optional object on every invocation of getTaskContextProvider(). Since this method can be called frequently, we should use a standard null check to avoid unnecessary object allocations.

      if (taskContextProvider == null) {
        taskContextProvider = taskContextProviderSupplier.get();
      }

Comment on lines 330 to 332
if (messagingService instanceof Service) {
((Service) messagingService).startAndWait();
((Service) messagingService).startAsync().awaitRunning();
}

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 messagingService is a shared global service, calling startAsync() directly when it is already running will throw an IllegalStateException. We should check if the service state is NEW before starting it.

Suggested change
if (messagingService instanceof Service) {
((Service) messagingService).startAndWait();
((Service) messagingService).startAsync().awaitRunning();
}
if (messagingService instanceof Service) {
Service service = (Service) messagingService;
if (service.state() == Service.State.NEW) {
service.startAsync().awaitRunning();
} else {
service.awaitRunning();
}
}

Comment on lines +344 to +353
applicationLifecycleService.startAsync();
programRuntimeService.startAsync();
metricsCollectionService.startAsync();
programNotificationSubscriberService.startAsync();
programStopSubscriberService.startAsync();
applicationLifecycleService.awaitRunning();
programRuntimeService.awaitRunning();
metricsCollectionService.awaitRunning();
programNotificationSubscriberService.awaitRunning();
programStopSubscriberService.awaitRunning();

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 metricsCollectionService is a shared global service, calling startAsync() directly when it is already running will throw an IllegalStateException. We should check if the service state is NEW before starting it.

Suggested change
applicationLifecycleService.startAsync();
programRuntimeService.startAsync();
metricsCollectionService.startAsync();
programNotificationSubscriberService.startAsync();
programStopSubscriberService.startAsync();
applicationLifecycleService.awaitRunning();
programRuntimeService.awaitRunning();
metricsCollectionService.awaitRunning();
programNotificationSubscriberService.awaitRunning();
programStopSubscriberService.awaitRunning();
applicationLifecycleService.startAsync();
programRuntimeService.startAsync();
if (metricsCollectionService.state() == Service.State.NEW) {
metricsCollectionService.startAsync();
}
programNotificationSubscriberService.startAsync();
programStopSubscriberService.startAsync();
applicationLifecycleService.awaitRunning();
programRuntimeService.awaitRunning();
metricsCollectionService.awaitRunning();
programNotificationSubscriberService.awaitRunning();
programStopSubscriberService.awaitRunning();

Comment on lines +199 to +205
try {

pluginInstantiator.close();

} catch (Exception ignored) {

}

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

If an exception is thrown before pluginInstantiator is initialized, it will be null in the catch block, and calling pluginInstantiator.close() will throw a NullPointerException. We should add an explicit null check.

      if (pluginInstantiator != null) {
        try {
          pluginInstantiator.close();
        } catch (Exception ignored) {
        }
      }

Comment on lines +163 to +169
try {

pluginInstantiator.close();

} catch (Exception ignored) {

}

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

If an exception is thrown before pluginInstantiator is initialized, it will be null in the catch block, and calling pluginInstantiator.close() will throw a NullPointerException. We should add an explicit null check.

      if (pluginInstantiator != null) {
        try {
          pluginInstantiator.close();
        } catch (Exception ignored) {
        }
      }

Comment on lines +87 to +90
try (java.io.InputStream in = Resources.asByteSource(url).openStream();
java.io.OutputStream out = new java.io.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 creating a FileOutputStream and copying bytes using ByteStreams.copy, we can use java.nio.file.Files.copy which is more concise, efficient, and consistent with other copy operations in this file.

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

This branch has not been deployed

No deployments
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.

4 participants