Skip to content

Conversation

Tobianas
Copy link
Contributor

@Tobianas Tobianas commented Sep 2, 2025

As reported by sonarcloud, these resources should be properly closed.

JIRA: LIGHTY-381

As reported by sonarcloud, these resources should be properly closed.

JIRA: LIGHTY-381
Signed-off-by: tobias.pobocik <[email protected]>
Copy link

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

Summary of Changes

Hello @Tobianas, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses resource management by ensuring that critical components within the Netconf topology and callhome plugins are properly closed when no longer needed. The changes prevent potential resource leaks and improve the overall stability and reliability of the system, aligning with best practices for resource handling in Java applications.

Highlights

  • Resource Closure Refactoring: Introduced a new private helper method, "closeResource", in both NetconfCallhomePlugin and NetconfTopologyPlugin to centralize and safely handle the closure of AutoCloseable resources, ensuring proper error logging.
  • Promoted Local Variables to Class Fields: Converted several locally scoped variables (e.g., mountStatusReporter, netconfTopologySchemaAssembler, timer, assembler) into class fields in both NetconfCallhomePlugin and NetconfTopologyPlugin. This change was necessary to make these resources accessible for proper closure during the stop procedure.
  • Enhanced Stop Procedure Logic: Updated the "stopProcedure" method in both plugins to utilize the new "closeResource" helper method, ensuring that all relevant resources are systematically closed upon plugin shutdown, addressing potential resource leaks identified by SonarCloud.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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 improves resource management by ensuring that various AutoCloseable resources are properly closed during shutdown. The new stopProcedure implementation is more robust as it attempts to close all resources even if one of them fails.

My review has identified a few areas for improvement:

  • A potential resource leak remains in NetconfCallhomePlugin as one of the AutoCloseable resources is not being closed.
  • There is some code duplication between NetconfCallhomePlugin and NetconfTopologyPlugin that could be refactored.
  • A minor style improvement regarding exception handling is also suggested.

Overall, this is a good change that improves the stability of the application. Please see the detailed comments for specific suggestions.

Comment on lines 69 to +77
protected boolean stopProcedure() {
boolean success = true;
success &= closeResource(dispatcher);
success &= closeResource(provider);
success &= closeResource(mountStatusReporter);
success &= closeResource(netconfTopologySchemaAssembler);
success &= closeResource(timer);
return success;
}

Choose a reason for hiding this comment

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

high

This method correctly closes several resources, but it appears to be missing one. The recorder variable, an instance of CallHomeMountStatusReporter created in the constructor, is also AutoCloseable and should be closed here to prevent a resource leak. Please consider storing it as a field and adding success &= closeResource(recorder); to this method to ensure it is properly closed on shutdown.

LOG.error("{} failed to close!", this.provider.getClass(), e);
resource.close();
return true;
} catch (Exception e) {

Choose a reason for hiding this comment

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

medium

Catching a generic Exception is generally discouraged, but it is necessary here since AutoCloseable.close() is declared to throw Exception. To acknowledge this and suppress potential static analysis warnings, it's good practice to add @SuppressWarnings("checkstyle:illegalCatch") to the closeResource method.

Comment on lines +88 to +99
private boolean closeResource(AutoCloseable resource) {
if (resource == null) {
return true;
}
try {
resource.close();
return true;
} catch (Exception e) {
LOG.error("{} failed to close!", resource.getClass().getName(), e);
return false;
}
}

Choose a reason for hiding this comment

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

medium

This closeResource helper method is identical to the one added in NetconfCallhomePlugin. To avoid code duplication and improve maintainability, consider extracting this logic into a shared utility class within the io.lighty.modules.southbound.netconf.impl package. The logger instance could be passed as a parameter to the utility method.

try {
resource.close();
return true;
} catch (Exception e) {

Choose a reason for hiding this comment

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

medium

Catching a generic Exception is generally discouraged, but it is necessary here since AutoCloseable.close() is declared to throw Exception. To acknowledge this and suppress potential static analysis warnings, it's good practice to add @SuppressWarnings("checkstyle:illegalCatch") to the closeResource method.

@Tobianas Tobianas closed this Sep 2, 2025
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