Skip to content

Commit

Permalink
Issue #43 address checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
njr-11 committed Oct 8, 2021
1 parent 4e3d0b6 commit d027c29
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions api/src/main/java/jakarta/enterprise/concurrent/Async.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
* @since 3.0
*/
public static class Result {
private static final ThreadLocal<CompletableFuture<?>> futures = new ThreadLocal<CompletableFuture<?>>();
private static final ThreadLocal<CompletableFuture<?>> FUTURES = new ThreadLocal<CompletableFuture<?>>();

/**
* Completes the {@link java.util.concurrent.CompletableFuture CompletableFuture}
Expand All @@ -248,11 +248,12 @@ public static class Result {
* @throws IllegalStateException if the <code>CompletableFuture</code> for an asynchronous
* method is not present on the thread.
*/
public static <T> CompletableFuture<T> complete(T result) {
public static <T> CompletableFuture<T> complete(final T result) {
@SuppressWarnings("unchecked")
CompletableFuture<T> future = (CompletableFuture<T>) futures.get();
if (future == null)
CompletableFuture<T> future = (CompletableFuture<T>) FUTURES.get();
if (future == null) {
throw new IllegalStateException();
}
future.complete(result);
return future;
}
Expand All @@ -271,9 +272,10 @@ public static <T> CompletableFuture<T> complete(T result) {
*/
public static <T> CompletableFuture<T> getFuture() {
@SuppressWarnings("unchecked")
CompletableFuture<T> future = (CompletableFuture<T>) futures.get();
if (future == null)
CompletableFuture<T> future = (CompletableFuture<T>) FUTURES.get();
if (future == null) {
throw new IllegalStateException();
}
return future;
}

Expand All @@ -293,11 +295,12 @@ public static <T> CompletableFuture<T> getFuture() {
* @param future <code>CompletableFuture</code> that the container returns to the caller,
* or <code>null</code> to clear it.
*/
public static <T> void setFuture(CompletableFuture<T> future) {
if (future == null)
futures.remove();
else
futures.set(future);
public static <T> void setFuture(final CompletableFuture<T> future) {
if (future == null) {
FUTURES.remove();
} else {
FUTURES.set(future);
}
}
}
}
}

0 comments on commit d027c29

Please sign in to comment.