Skip to content

avoid generating NullPointerException while closing IO #2533

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

Merged
merged 2 commits into from
May 5, 2022

Conversation

cszxyang
Copy link
Contributor

minor code changes

@harawata
Copy link
Member

I don't know...it seems to be the caller's responsibility to close the Reader/InputStream.
I would rather remove the close() calls.

@kazuki43zoo @christianpoitras
Does Spring or Guice module need these close() calls?

@awxiaoxian2020
Copy link
Contributor

I don't know...it seems to be the caller's responsibility to close the Reader/InputStream. I would rather remove the close() calls.

@kazuki43zoo @christianpoitras Does Spring or Guice module need these close() calls?

Hello, @harawata
What you are talking about is the question of whether the call should exist, and the contribution he has made is worthy of recognition when the call currently already exists. Because this pattern of close() is quite common and it's safe indeed. :)
ref: the I/O tutorial in Oracle

@awxiaoxian2020
Copy link
Contributor

I don't know...it seems to be the caller's responsibility to close the Reader/InputStream. I would rather remove the close() calls.

@kazuki43zoo @christianpoitras Does Spring or Guice module need these close() calls?

@harawata FYI:
in our getting-started doc, we says:

This class can be instantiated, used and thrown away. There is no need to keep it around once you've created your SqlSessionFactory. Therefore the best scope for instances of SqlSessionFactoryBuilder is method scope (i.e. a local method variable).

So the I/O stream will only use once in most cases. It is possible that the user should close the I/O stream, but it is not necessary. As a framework, it's reasonable we close the I/O stream. And MyBatis last the pattern a long time, if we romove it, there are some usage habits change for users.

@coveralls
Copy link

coveralls commented May 5, 2022

Coverage Status

Coverage increased (+0.08%) to 87.302% when pulling 7ecd3f6 on cszxyang:feature_npt_avoid into 774a52d on mybatis:master.

@harawata harawata merged commit de6aaa9 into mybatis:master May 5, 2022
@harawata
Copy link
Member

harawata commented May 5, 2022

Thank you, @cszxyang @awxiaoxian2020 !

@harawata harawata self-assigned this May 5, 2022
@harawata harawata added the polishing Improve a implementation code or doc without change in current behavior/content label May 5, 2022
@harawata harawata added this to the 3.5.10 milestone May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
polishing Improve a implementation code or doc without change in current behavior/content
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants