From: Niki Roo Date: Tue, 26 May 2020 19:08:11 +0000 (+0200) Subject: throw IO when image is used on close X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=4bcaece93026850c1f6669c288f52b7356c62a4c;p=fanfix-swing.git throw IO when image is used on close --- diff --git a/src/be/nikiroo/utils/Image.java b/src/be/nikiroo/utils/Image.java index 4518577d..9b28835e 100644 --- a/src/be/nikiroo/utils/Image.java +++ b/src/be/nikiroo/utils/Image.java @@ -116,7 +116,13 @@ public class Image implements Closeable, Serializable { * in case of I/O error */ public InputStream newInputStream() throws IOException { - return new MarkableFileInputStream(data); + synchronized (instanceLock) { + if (data == null) { + throw new IOException("Image was close()d"); + } + + return new MarkableFileInputStream(data); + } } /** @@ -175,6 +181,7 @@ public class Image implements Closeable, Serializable { @Override public void close() throws IOException { synchronized (instanceLock) { + new Exception().printStackTrace(); if (size >= 0) { size = -1; data.delete();