-
Notifications
You must be signed in to change notification settings - Fork 642
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
[ISSUE #4098] Method may fail to clean up stream or resource[WatchFileManagerTest] #4274
Conversation
properties.setProperty("eventMesh.server.newAdd", "newAdd"); | ||
properties.store(fw, "newAdd"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use log4j instead.
try (FileReader fr = new FileReader(file); | ||
BufferedReader br = new BufferedReader(fr); | ||
FileWriter fw = new FileWriter(file)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job.
When using .close()
to close nested streams, we only need to close the outermost stream, because the close request propagates from the outermost stream to the innermost stream.
To have try-with-resources close them, you assigned the streams to variables as you opened them, instead of nesting. If you used nesting, an exception during construction of one of the later streams (e.g. GZIPOutputStream
) will leave any stream constructed by the nested calls inside it open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kyooosukedn Test case failed, Pls fix it
Ref:
|
Hi @kyooosukedn , the issue has been accomplished in #4716. Do you have any additional information to share? Feel free to share your latest insights with us. If you feel that your issue has been resolved, you are welcome to close it. We sincerely appreciate your contributions to Apache EventMesh. |
It seems like the issue is closed properly. I will close this :) |
Fixes #4098.
Motivation
Method may fail to clean up stream or resource
Explain why you want to make the changes and what problem you're trying to solve.
Modifications
Used try with resources to manage resources
Documentation