Skip to content

Commit f070e3c

Browse files
authored
Annotate CompletionService classes. (#124)
Compare google/xplat@9de0f25 (which missed `@Nullable` on the `poll` methods, so I'll be fixing that later).
1 parent fdbe771 commit f070e3c

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/java.base/share/classes/java/util/concurrent/CompletionService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
package java.util.concurrent;
3737

38+
import org.jspecify.annotations.NullMarked;
39+
import org.jspecify.annotations.Nullable;
40+
3841
/**
3942
* A service that decouples the production of new asynchronous tasks
4043
* from the consumption of the results of completed tasks. Producers
@@ -62,7 +65,8 @@
6265
*
6366
* @since 1.5
6467
*/
65-
public interface CompletionService<V> {
68+
@NullMarked
69+
public interface CompletionService<V extends @Nullable Object> {
6670
/**
6771
* Submits a value-returning task for execution and returns a Future
6872
* representing the pending results of the task. Upon completion,
@@ -108,7 +112,7 @@ public interface CompletionService<V> {
108112
* @return the Future representing the next completed task, or
109113
* {@code null} if none are present
110114
*/
111-
Future<V> poll();
115+
@Nullable Future<V> poll();
112116

113117
/**
114118
* Retrieves and removes the Future representing the next
@@ -124,5 +128,5 @@ public interface CompletionService<V> {
124128
* before one is present
125129
* @throws InterruptedException if interrupted while waiting
126130
*/
127-
Future<V> poll(long timeout, TimeUnit unit) throws InterruptedException;
131+
@Nullable Future<V> poll(long timeout, TimeUnit unit) throws InterruptedException;
128132
}

src/java.base/share/classes/java/util/concurrent/ExecutorCompletionService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
package java.util.concurrent;
3737

38+
import org.jspecify.annotations.NullMarked;
39+
import org.jspecify.annotations.Nullable;
40+
3841
/**
3942
* A {@link CompletionService} that uses a supplied {@link Executor}
4043
* to execute tasks. This class arranges that submitted tasks are,
@@ -102,7 +105,8 @@
102105
*
103106
* @since 1.5
104107
*/
105-
public class ExecutorCompletionService<V> implements CompletionService<V> {
108+
@NullMarked
109+
public class ExecutorCompletionService<V extends @Nullable Object> implements CompletionService<V> {
106110
private final Executor executor;
107111
private final AbstractExecutorService aes;
108112
private final BlockingQueue<Future<V>> completionQueue;
@@ -202,11 +206,11 @@ public Future<V> take() throws InterruptedException {
202206
return completionQueue.take();
203207
}
204208

205-
public Future<V> poll() {
209+
public @Nullable Future<V> poll() {
206210
return completionQueue.poll();
207211
}
208212

209-
public Future<V> poll(long timeout, TimeUnit unit)
213+
public @Nullable Future<V> poll(long timeout, TimeUnit unit)
210214
throws InterruptedException {
211215
return completionQueue.poll(timeout, unit);
212216
}

0 commit comments

Comments
 (0)