Skip to content

[#4182] improvement: close the input file stream#4224

Merged
justinmclean merged 1 commit intoapache:mainfrom
pravo23:close_file_input
Jul 22, 2024
Merged

[#4182] improvement: close the input file stream#4224
justinmclean merged 1 commit intoapache:mainfrom
pravo23:close_file_input

Conversation

@pravo23
Copy link
Contributor

@pravo23 pravo23 commented Jul 21, 2024

What changes were proposed in this pull request?

Added try block for handling file input operations to ensure the file is properly closed even if an error occurs.

Why are the changes needed?

Fix: #4182

Does this PR introduce any user-facing change?

No

How was this patch tested?

existing tests

Signed-off-by: pravo23 <pravo23@192.168.1.6>
try (FileInputStream input = new FileInputStream(configFileName)) {
properties.load(input);
}

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for helping out here. Is this code complete as it looks like the input stream is still not closed?

Copy link
Contributor

Choose a reason for hiding this comment

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

@justinmclean
The try/catch code block will close the input automatically, please refer to try-with-resource

Copy link
Member

Choose a reason for hiding this comment

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

OK, that looks good to me

@justinmclean justinmclean merged commit 38fe815 into apache:main Jul 22, 2024
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.

[Improvement] FileInputStream is not closed

3 participants