Skip to content

Commit de6aaa9

Browse files
authored
Merge pull request #2533 from cszxyang/feature_npt_avoid
avoid generating NullPointerException while closing IO
2 parents 869bb95 + 7ecd3f6 commit de6aaa9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/main/java/org/apache/ibatis/session/SqlSessionFactoryBuilder.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2021 the original author or authors.
2+
* Copyright 2009-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -53,7 +53,9 @@ public SqlSessionFactory build(Reader reader, String environment, Properties pro
5353
} finally {
5454
ErrorContext.instance().reset();
5555
try {
56-
reader.close();
56+
if (reader != null) {
57+
reader.close();
58+
}
5759
} catch (IOException e) {
5860
// Intentionally ignore. Prefer previous error.
5961
}
@@ -81,7 +83,9 @@ public SqlSessionFactory build(InputStream inputStream, String environment, Prop
8183
} finally {
8284
ErrorContext.instance().reset();
8385
try {
84-
inputStream.close();
86+
if (inputStream != null) {
87+
inputStream.close();
88+
}
8589
} catch (IOException e) {
8690
// Intentionally ignore. Prefer previous error.
8791
}

0 commit comments

Comments
 (0)