Skip to content
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

The code may throw an exception before the tc is closed,you should use try-catch-finally or try-with-resource to close resource #4594

Closed
QiAnXinCodeSafe opened this issue Dec 29, 2020 · 0 comments · Fixed by #4606
Assignees

Comments

@QiAnXinCodeSafe
Copy link

QiAnXinCodeSafe commented Dec 29, 2020

try {
tc = new FileOutputStream(tf).getChannel();
sc = new FileInputStream(sf).getChannel();
sc.transferTo(0, sc.size(), tc);
} finally {
if (null != sc) {
sc.close();
}
if (null != tc) {
tc.close();
}
}

sc.close() may be throw an exception

conn.getOutputStream().write(b, 0, b.length);
conn.getOutputStream().flush();
conn.getOutputStream().close();

InputStream in = getResourceAsStream(loader, resource);
props.load(in);
in.close();

@Maijh97 Maijh97 self-assigned this Dec 30, 2020
Maijh97 added a commit to Maijh97/nacos that referenced this issue Dec 30, 2020
wjm0729 added a commit to wjm0729/nacos that referenced this issue Dec 31, 2020
…op-import-v2

* 'develop' of https://github.com/alibaba/nacos:
  优化 FileTypeEnum 取值逻辑, 避免使用异常当作逻辑分支 (alibaba#4607)
  for alibaba#4594,alibaba#4594 Fix IO close problem. (alibaba#4606)
  console-ui config排序优化 (alibaba#4599)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants