You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/01/27 22:37:01 UTC
(commons-io) branch master updated: RandomAccessFileInputStream.builder().get() now throws ISE instead of NPE
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new 6dbf4973 RandomAccessFileInputStream.builder().get() now throws ISE instead of NPE
6dbf4973 is described below
commit 6dbf49738607b107497e89b483bacf905337c7bb
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 27 17:36:56 2024 -0500
RandomAccessFileInputStream.builder().get() now throws ISE instead of
NPE
---
src/changes/changes.xml | 1 +
.../org/apache/commons/io/input/RandomAccessFileInputStream.java | 2 +-
.../apache/commons/io/input/RandomAccessFileInputStreamTest.java | 6 ++++++
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4fcbcdcb..4fd5b2a3 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -102,6 +102,7 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="fix" due-to="Gary Gregory">Deprecate RandomAccessFiles 0-argument constructor.</action>
<action dev="ggregory" type="fix" due-to="Elliotte Rusty Harold, Gary Gregory">Clarify and correct EndianUtils and SwappedDataInputStream API doc #566.</action>
<action dev="ggregory" type="fix" due-to="Elliotte Rusty Harold">Add characterization test for copying a symlinked directory #570.</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">RandomAccessFileInputStream.builder().get() now throws ISE instead of NPE.</action>
<!-- Add -->
<action dev="ggregory" type="add" due-to="Gary Gregory">Add and use PathUtils.getFileName(Path, Function<Path, R>).</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">Add and use PathUtils.getFileNameString().</action>
diff --git a/src/main/java/org/apache/commons/io/input/RandomAccessFileInputStream.java b/src/main/java/org/apache/commons/io/input/RandomAccessFileInputStream.java
index 647ee4d1..07a8a979 100644
--- a/src/main/java/org/apache/commons/io/input/RandomAccessFileInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/RandomAccessFileInputStream.java
@@ -79,7 +79,7 @@ public class RandomAccessFileInputStream extends InputStream {
}
return new RandomAccessFileInputStream(randomAccessFile, closeOnClose);
}
- return new RandomAccessFileInputStream(RandomAccessFileMode.READ_ONLY.create(getOrigin().getFile()), closeOnClose);
+ return new RandomAccessFileInputStream(RandomAccessFileMode.READ_ONLY.create(checkOrigin().getFile()), closeOnClose);
}
/**
diff --git a/src/test/java/org/apache/commons/io/input/RandomAccessFileInputStreamTest.java b/src/test/java/org/apache/commons/io/input/RandomAccessFileInputStreamTest.java
index 80137c9d..0892d3a7 100644
--- a/src/test/java/org/apache/commons/io/input/RandomAccessFileInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/RandomAccessFileInputStreamTest.java
@@ -74,6 +74,12 @@ public class RandomAccessFileInputStreamTest {
}
}
+ @Test
+ public void testBuilderGet() {
+ // java.lang.IllegalStateException: origin == null
+ assertThrows(IllegalStateException.class, () -> RandomAccessFileInputStream.builder().get());
+ }
+
@SuppressWarnings("resource") // instance variable access
@Test
public void testBuilderPath() throws IOException {