From 4bcaece93026850c1f6669c288f52b7356c62a4c Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Tue, 26 May 2020 21:08:11 +0200 Subject: [PATCH] throw IO when image is used on close --- src/be/nikiroo/utils/Image.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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(); -- 2.27.0