Skip to content

Commit 7f3b781

Browse files
authored
Remove unnecessary InputStream.close call (#1982)
#1942 changed the way that the bootstrap init script is handled, but it added an extra `InputStream.close` call that shouldn't be needed after the BufferedReader [here](https://github.com/apache/polaris/pull/1942/files#diff-de43b240b5b5e07aba7e89f5515a417cefd908845b85432f3fcc0819911f3e2eR89) is closed. This PR removes that extra call.
1 parent c5907e6 commit 7f3b781

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperations.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,15 @@ DatabaseType getDatabaseType() {
8282
* @throws SQLException : Exception while executing the script.
8383
*/
8484
public void executeScript(InputStream scriptInputStream) throws SQLException {
85-
try {
85+
try (BufferedReader scriptReader =
86+
new BufferedReader(
87+
new InputStreamReader(Objects.requireNonNull(scriptInputStream), UTF_8))) {
88+
List<String> scriptLines = scriptReader.lines().toList();
8689
runWithinTransaction(
8790
connection -> {
88-
try (Statement statement = connection.createStatement();
89-
BufferedReader reader =
90-
new BufferedReader(
91-
new InputStreamReader(Objects.requireNonNull(scriptInputStream), UTF_8))) {
91+
try (Statement statement = connection.createStatement()) {
9292
StringBuilder sqlBuffer = new StringBuilder();
93-
String line;
94-
while ((line = reader.readLine()) != null) {
93+
for (String line : scriptLines) {
9594
line = line.trim();
9695
if (!line.isEmpty() && !line.startsWith("--")) { // Ignore empty lines and comments
9796
sqlBuffer.append(line).append("\n");
@@ -110,16 +109,10 @@ public void executeScript(InputStream scriptInputStream) throws SQLException {
110109
}
111110
}
112111
return true;
113-
} catch (IOException e) {
114-
throw new RuntimeException(e);
115112
}
116113
});
117-
} finally {
118-
try {
119-
scriptInputStream.close();
120-
} catch (IOException e) {
121-
LOGGER.error("Failed to close input stream: {}", e.getMessage());
122-
}
114+
} catch (IOException e) {
115+
throw new RuntimeException(e);
123116
}
124117
}
125118

0 commit comments

Comments
 (0)