Assign unused Future return value to a variable

Error Prone plans to make this pattern into a compile error; this avoids
future breakage.

In some of these cases, it's not obvious that ignoring the return value
is the correct thing to do; the hope is that the construct is ugly
enough to make the author think twice. In many cases though, it's clear
that a locally-created Runnable or Callable already does its own error
handling, so we can leave a comment alongside the ignored return value.

Eventually many of these should be audited again, and we can replace
some of the @SuppressWarnings with Error Prone's @CanIgnoreReturnValue.
That much is left for future cleanup.

Change-Id: Ia989214d85e0d6c387e388a77178e0b5c4bf2498
This commit is contained in:
Dave Borowitz
2017-02-02 15:49:50 -05:00
parent a00f42a52f
commit 9189e67c3d
19 changed files with 160 additions and 103 deletions

View File

@@ -49,6 +49,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
@@ -169,22 +170,28 @@ public class GerritServer {
} else {
site = initSite(cfg);
daemonService = Executors.newSingleThreadExecutor();
daemonService.submit(
new Callable<Void>() {
@Override
public Void call() throws Exception {
int rc =
daemon.main(
new String[] {
"-d", site.getPath(), "--headless", "--console-log", "--show-stack-trace",
});
if (rc != 0) {
System.err.println("Failed to start Gerrit daemon");
serverStarted.reset();
}
return null;
}
});
@SuppressWarnings("unused")
Future<?> possiblyIgnoredError =
daemonService.submit(
new Callable<Void>() {
@Override
public Void call() throws Exception {
int rc =
daemon.main(
new String[] {
"-d",
site.getPath(),
"--headless",
"--console-log",
"--show-stack-trace",
});
if (rc != 0) {
System.err.println("Failed to start Gerrit daemon");
serverStarted.reset();
}
return null;
}
});
serverStarted.await();
System.out.println("Gerrit Server Started");
}