Skip to content

Commit dbba1ff

Browse files
committed
Calling QueueInputStream.QueueInputStream(null) maps to the same kind of
default blocking queue as QueueInputStream.Builder.setBlockingQueue(null)
1 parent 1d4ede0 commit dbba1ff

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ The <action> type attribute can be add,update,fix,remove.
7272
<action dev="ggregory" type="fix" due-to="Gary Gregory">FileTimes.toNtfsTime(*) methods can overflow result values.</action>
7373
<action dev="ggregory" type="fix" due-to="Gary Gregory">Fix Javadoc for ChunkedOutputStream.Builder.</action>
7474
<action dev="ggregory" type="fix" due-to="Gary Gregory">General Javadoc improvements.</action>
75+
<action dev="ggregory" type="fix" due-to="Gary Gregory">Calling QueueInputStream.QueueInputStream(null) maps to the same kind of default blocking queue as QueueInputStream.Builder.setBlockingQueue(null).</action>
7576
<!-- ADD -->
7677
<action dev="ggregory" type="add" issue="IO-860" due-to="Nico Strecker, Gary Gregory">Add ThrottledInputStream.Builder.setMaxBytes(long, ChronoUnit).</action>
7778
<action dev="ggregory" type="add" due-to="Gary Gregory">Add IOIterable.</action>

src/main/java/org/apache/commons/io/input/QueueInputStream.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ public Builder() {
106106
*/
107107
@Override
108108
public QueueInputStream get() {
109-
return new QueueInputStream(blockingQueue, timeout);
109+
return new QueueInputStream(this);
110110
}
111111

112112
/**
113113
* Sets backing queue for the stream.
114114
*
115-
* @param blockingQueue backing queue for the stream.
115+
* @param blockingQueue backing queue for the stream, null resets to a new blocking queue instance.
116116
* @return {@code this} instance.
117117
*/
118118
public Builder setBlockingQueue(final BlockingQueue<Integer> blockingQueue) {
@@ -160,23 +160,22 @@ public QueueInputStream() {
160160
/**
161161
* Constructs a new instance with given queue and zero timeout.
162162
*
163-
* @param blockingQueue backing queue for the stream.
163+
* @param blockingQueue backing queue for the stream, null maps to a new blocking queue instance.
164164
* @deprecated Use {@link #builder()}, {@link Builder}, and {@link Builder#get()}.
165165
*/
166166
@Deprecated
167167
public QueueInputStream(final BlockingQueue<Integer> blockingQueue) {
168-
this(blockingQueue, Duration.ZERO);
168+
this(builder().setBlockingQueue(blockingQueue));
169169
}
170170

171171
/**
172-
* Constructs a new instance with given queue and timeout.
172+
* Constructs a new instance.
173173
*
174-
* @param blockingQueue backing queue for the stream.
175-
* @param timeout how long to wait before giving up when polling the queue.
174+
* @param builder The builder.
176175
*/
177-
private QueueInputStream(final BlockingQueue<Integer> blockingQueue, final Duration timeout) {
178-
this.blockingQueue = Objects.requireNonNull(blockingQueue, "blockingQueue");
179-
this.timeoutNanos = Objects.requireNonNull(timeout, "timeout").toNanos();
176+
private QueueInputStream(final Builder builder) {
177+
this.blockingQueue = Objects.requireNonNull(builder.blockingQueue, "blockingQueue");
178+
this.timeoutNanos = Objects.requireNonNull(builder.timeout, "timeout").toNanos();
180179
}
181180

182181
/**

src/test/java/org/apache/commons/io/input/QueueInputStreamTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ public void testBufferedWrites(final String inputData) throws IOException {
159159

160160
@Test
161161
public void testInvalidArguments() {
162-
assertThrows(NullPointerException.class, () -> new QueueInputStream(null), "queue is required");
163162
assertThrows(IllegalArgumentException.class, () -> QueueInputStream.builder().setTimeout(Duration.ofMillis(-1)).get(), "waitTime must not be negative");
164163
}
165164

0 commit comments

Comments
 (0)