Skip to content

Use try-with-resources in HttpTunnelPayload #11779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Use try-with-resources in HttpTunnelPayload #11779

wants to merge 3 commits into from

Conversation

rajadilipkolli
Copy link
Contributor

@rajadilipkolli rajadilipkolli commented Jan 25, 2018

Resources are not closed, hence closing using try-with-resources block

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 25, 2018
@philwebb philwebb added type: enhancement A general enhancement priority: normal for: merge-with-amendments Needs some changes when we merge and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 25, 2018
@philwebb philwebb self-assigned this Jan 25, 2018
@philwebb
Copy link
Member

Thanks. I'm not sure if all of these are valid or not so will review before merging.

@igor-suhorukov
Copy link
Contributor

@rajadilipkolli @philwebb thank you for attention to this issues! But this is false positive static code analysis warning. Possible resource leak already fixed in PR 11624

Need to redesign this classes to avoid this sonarcloud warnings.

Log4J2LoggingSystem.java is not applicable - stream should be in open state after return of ConfigurationSource

JarWriter.java - output stream created in construnctor and used in another object methods

SocketTargetServerConnection.java - network channel should be in open state after method return

@igor-suhorukov
Copy link
Contributor

igor-suhorukov commented Jan 25, 2018

HttpTunnelPayload.java looks like real fix (if exception occurred)
TunnelClient.java - false positive
ArtemisConnectionFactoryFactory.java - false positive

@philwebb philwebb added this to the 2.2.x milestone Jun 14, 2019
@philwebb philwebb removed their assignment Sep 18, 2019
@wilkinsona wilkinsona self-assigned this Sep 18, 2019
if (launchScript != null) {
fileOutputStream.write(launchScript.toByteArray());
setExecutableFilePermission(file);
try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
Copy link
Member

@wilkinsona wilkinsona Sep 18, 2019

Choose a reason for hiding this comment

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

This will close fileOutputStream before it can be written to via this.jarOutput. It's eventually closed when JarWriter is closed so this is change isn't needed. I'll address this while merging.

.createServerLocatorWithoutHA(transportConfiguration);
return factoryClass.getConstructor(ServerLocator.class)
.newInstance(serviceLocator);
try (ServerLocator serviceLocator = ActiveMQClient
Copy link
Member

@wilkinsona wilkinsona Sep 18, 2019

Choose a reason for hiding this comment

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

This will close the ServerLocator before the connection factory can use it. It is eventually closed when the connection factory is closed so this change is unnecessary. I'll address this when merging.

this.serverThread = new ServerThread(serverSocketChannel);
this.serverThread.start();
return port;
try (ServerSocketChannel serverSocketChannel = ServerSocketChannel.open()) {
Copy link
Member

Choose a reason for hiding this comment

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

This will close the ServerSocketChannel before it can be used by the ServerThread. The channel is eventually closed when the thread is closed so this change is unnecessary. I'll address this when merging.

SocketChannel channel = SocketChannel.open(address);
channel.socket().setSoTimeout(socketTimeout);
return new TimeoutAwareChannel(channel);
try (SocketChannel channel = SocketChannel.open(address)) {
Copy link
Member

Choose a reason for hiding this comment

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

This will close the SocketChannel before it can be used by TimeoutAwareChannel. It's eventually closed when the TimeoutAwareChannel is closed so this is change isn't needed. I'll address this while merging.

InputStream stream = url.openStream();
if (FILE_PROTOCOL.equals(url.getProtocol())) {
return new ConfigurationSource(stream, ResourceUtils.getFile(url));
try (InputStream stream = url.openStream()) {
Copy link
Member

Choose a reason for hiding this comment

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

This will close the InputStream before it can be retrieved from the ConfigurationSource and used. Log4j2 makes it the responsibility of the user of the ConfigurationSource to retrieve the InputStream and close it so this change is unnecessary.

@wilkinsona wilkinsona changed the title Cleanup potential Resource Leakage Use try-with-resources in HttpTunnelPayload Sep 18, 2019
@wilkinsona wilkinsona added type: task A general task and removed type: enhancement A general enhancement labels Sep 18, 2019
wilkinsona pushed a commit that referenced this pull request Sep 18, 2019
@wilkinsona wilkinsona modified the milestones: 2.2.x, 2.2.0.RC1 Sep 18, 2019
pull bot pushed a commit to scope-demo/spring-boot that referenced this pull request Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: merge-with-amendments Needs some changes when we merge type: task A general task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants