diff --git a/ChangeLog.txt b/ChangeLog.txt index 6663d0af..7d3143e9 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -16,6 +16,13 @@ instead of -1 if width was < 1. [5] The Huffman encoder now uses clz and bsr instructions for bit counting on ARM64 platforms (see 1.4 beta1 [5].) +[6] The close() method in the TJCompressor and TJDecompressor Java classes is +now idempotent. Previously, that method would call the native tjDestroy() +function even if the TurboJPEG instance had already been destroyed. This +caused an exception to be thrown during finalization, if the close() method had +already been called. The exception was caught, but it was still an expensive +operation. + 1.3.90 (1.4 beta1) ================== diff --git a/java/org/libjpegturbo/turbojpeg/TJCompressor.java b/java/org/libjpegturbo/turbojpeg/TJCompressor.java index c4a8cc58..a780d15a 100644 --- a/java/org/libjpegturbo/turbojpeg/TJCompressor.java +++ b/java/org/libjpegturbo/turbojpeg/TJCompressor.java @@ -567,7 +567,8 @@ public class TJCompressor { * Free the native structures associated with this compressor instance. */ public void close() throws Exception { - destroy(); + if (handle != 0) + destroy(); } protected void finalize() throws Throwable { diff --git a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java index 1a2774c0..876ff8f0 100644 --- a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java +++ b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java @@ -834,7 +834,8 @@ public class TJDecompressor { * Free the native structures associated with this decompressor instance. */ public void close() throws Exception { - destroy(); + if (handle != 0) + destroy(); } protected void finalize() throws Throwable {