From c171a95679a906aa41d48b62a49e6e67507ceb5f Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Thu, 16 May 2024 23:28:12 +0900 Subject: [PATCH] fix: guard `close` with null-check to avoid NPE --- README.md | 1 + .../org/dts/spell/dictionary/myspell/MySpell.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0cbf51c..b2f2303 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ This repository is a forked jmyspell-core project used for OmegaT project. - use `isEmpty()` for condition that compare with zero length - fix: define `Word#hashCode`, `Word` class already has `equals` definition - fix: unwanted raw types + - fix: check nullity of stream before close - style: apply spotbugs - Quality assurance by checking with SpotBugs static code analysis - CI: test with GitHub Actions diff --git a/src/main/java/org/dts/spell/dictionary/myspell/MySpell.java b/src/main/java/org/dts/spell/dictionary/myspell/MySpell.java index 00571a4..f104881 100644 --- a/src/main/java/org/dts/spell/dictionary/myspell/MySpell.java +++ b/src/main/java/org/dts/spell/dictionary/myspell/MySpell.java @@ -65,10 +65,14 @@ else if (entry.getName().endsWith(".dic")) dStream = zipFile.getInputStream(entry) ; } - initFromStreams(affStream, dStream) ; - - affStream.close() ; - dStream.close() ; + initFromStreams(affStream, dStream) ; + + if (affStream != null) { + affStream.close() ; + } + if (dStream != null) { + dStream.close() ; + } } public MySpell(InputStream zipStream) throws IOException