RandomAccessFileInputStream.builder().get() now throws ISE instead of
NPE
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4fcbcdc..4fd5b2a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -102,6 +102,7 @@
<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 647ee4d..07a8a97 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 @@
}
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 80137c9..0892d3a 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 @@
}
}
+ @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 {