From c6fa10de6e8baeae700b1c3eb39d7210ed48e864 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Tue, 22 Nov 2022 18:14:25 +0100 Subject: [PATCH] Fix file descriptor leak --- .../schema/internal/exec/ScriptSourceInputFromUrl.java | 2 +- .../test/tool/schema/DefaultImportFileExecutionTest.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromUrl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromUrl.java index 8229327094..76222dfe3c 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromUrl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/ScriptSourceInputFromUrl.java @@ -60,7 +60,7 @@ public class ScriptSourceInputFromUrl extends AbstractScriptSourceInput { @Override protected void releaseReader(Reader reader) { try { - prepareReader().close(); + reader.close(); } catch (IOException e) { log.warn( "Unable to close file reader for generation script source" ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/tool/schema/DefaultImportFileExecutionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/tool/schema/DefaultImportFileExecutionTest.java index 2d720d9f9c..0428607c58 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/tool/schema/DefaultImportFileExecutionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/tool/schema/DefaultImportFileExecutionTest.java @@ -2,7 +2,9 @@ package org.hibernate.orm.test.tool.schema; import java.io.File; import java.io.FileWriter; +import java.io.IOException; import java.net.URL; +import java.nio.file.Files; import java.util.ArrayList; import java.util.EnumSet; import java.util.HashMap; @@ -56,7 +58,12 @@ public class DefaultImportFileExecutionTest { public void tearDown() { serviceRegistry.close(); if ( defaultImportFile.exists() ) { - defaultImportFile.delete(); + try { + Files.delete( defaultImportFile.toPath() ); + } + catch (IOException e) { + throw new RuntimeException( e ); + } } }