diff --git a/indexing-hadoop/src/main/java/org/apache/druid/indexer/JobHelper.java b/indexing-hadoop/src/main/java/org/apache/druid/indexer/JobHelper.java index c047c2b34e4..7d99d03ad56 100644 --- a/indexing-hadoop/src/main/java/org/apache/druid/indexer/JobHelper.java +++ b/indexing-hadoop/src/main/java/org/apache/druid/indexer/JobHelper.java @@ -370,10 +370,12 @@ public class JobHelper { if (hadoopJobId != null && hadoopJobIdFileName != null) { try (final OutputStream out = Files.newOutputStream(Paths.get(hadoopJobIdFileName))) { - HadoopDruidIndexerConfig.JSON_MAPPER.writeValue( - new OutputStreamWriter(out, StandardCharsets.UTF_8), - hadoopJobId - ); + try (final OutputStreamWriter osw = new OutputStreamWriter(out, StandardCharsets.UTF_8)) { + HadoopDruidIndexerConfig.JSON_MAPPER.writeValue( + osw, + hadoopJobId + ); + } log.info("MR job id [%s] is written to the file [%s]", hadoopJobId, hadoopJobIdFileName); } catch (IOException e) {