Future
s should not be ignored JAVA-W1087257 */
258 public static void whenComplete(final CompletableFuture<?> completableFuture,
259 final Runnable whenComplete) {
260 completableFuture.whenComplete((o, throwable) -> {261 if (throwable != null) {262 throw new IllegalStateException(throwable);263 }264 whenComplete.run();265 });266 }
267
268 public static void runBukkitSync(final Runnable runnable, final int delay) {
448 }
449
450 private <T> void onCompletion(final CompletableFuture<T> future, final Consumer<T> consumer) {
451 future.whenComplete((t, throwable) -> {452 if (throwable != null) {453 throwable.printStackTrace();454 return;455 }456 consumer.accept(t);457 });458 }
459
460 public enum ResetType {
314 .getDataFolder());
315 completableFutures[1] = ConfigurationManager.INSTANCE.reload();
316
317 CompletableFuture.allOf(completableFutures)318 .whenComplete((unused, throwable) -> {319 // reloading the blocks320 BlockMenuManager.INSTANCE.reload();321322 if (player.getPlayer() != null) {323 BridgeUtil.sendMessage(player, INSTANCE.reloaded);324 }325 });326 }
327
328 @Subcommand("help")
131 });
132
133 log("Loading the messages...");
134 Message.load(javaPlugin.getDataFolder());135
136 log("Generating `/sb help` message...");
137 HelpCommandGenerator.generateHelpCommand(javaPlugin);
Always use the value returned by a method with return type Future<T>
.
When a method returns a Future
, it means the result of its computation will only be available at a later time, not immediately. It is possible that the operation may fail with an exception, or may have some useful result.
If the return value is ignored, such data will be lost.
If, however, there truly is no reason to use the result of the future, consider marking this call with a // skipcq: JAVA-W1087
comment to avoid reporting this issue. This issue will also respect suppression via SuppressWarnings("unused")
.
CompletableFuture<String> returnsFuture() {
return someImportantDataInAFuture;
}
void consumer() {
returnsFuture(); // Bad!
}
Even if there is no use for the data, consider adding a handler to process any exceptions that may have occurred during the future's execution.
returnsFuture().handle((v, e) -> {
if (e != null)
logger.error("An error occurred.", e);
});