From 0b21605996a66c4e879074f0ab5286f5789ff111 Mon Sep 17 00:00:00 2001 From: Jorge Bescos Gascon Date: Tue, 2 Apr 2024 09:23:45 +0200 Subject: [PATCH] Add Objects.requireNonNull(this) in newStream Signed-off-by: Jorge Bescos Gascon --- .../mail/util/SharedFileInputStream.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/jakarta/mail/util/SharedFileInputStream.java b/api/src/main/java/jakarta/mail/util/SharedFileInputStream.java index 8d62026b..4df19084 100644 --- a/api/src/main/java/jakarta/mail/util/SharedFileInputStream.java +++ b/api/src/main/java/jakarta/mail/util/SharedFileInputStream.java @@ -476,15 +476,19 @@ public long getPosition() { */ @Override public synchronized InputStream newStream(long start, long end) { - if (in == null) - throw new RuntimeException("Stream closed"); - if (start < 0) - throw new IllegalArgumentException("start < 0"); - if (end == -1) - end = datalen; - - return new SharedFileInputStream(sf, - this.start + start, end - start, bufsize); + try { + if (in == null) + throw new RuntimeException("Stream closed"); + if (start < 0) + throw new IllegalArgumentException("start < 0"); + if (end == -1) + end = datalen; + + return new SharedFileInputStream(sf, + this.start + start, end - start, bufsize); + } finally { + Objects.requireNonNull(this); //TODO: replace with Reference.reachabilityFence + } } // for testing...