Future
s should not be ignored JAVA-W1087 83 }
84
85 public <T> void doQuery(final String sql, final Consumer<T> consumer, final String field, final Class<T> type) {
86 CompletableFuture.runAsync(() -> { 87 try (Connection connection = getConnection(); 88 PreparedStatement ps = connection.prepareStatement(sql); 89 ResultSet result = ps.executeQuery()) { 90 if (result.next()) { 91 final T value = result.getObject(field, type); 92 consumer.accept(value); 93 } 94 } catch (final SQLException e) { 95 log("Failed to do query", e); 96 } 97 }); 98 }
99
100 /**
28
29 private void setup() {
30 if (Settings.isUpdateCheck()) {
31 ScheduleUtils.runAsyncTimer(this::checkForUpdates, 3, 18000, TimeUnit.SECONDS);32 }
33 }
34
157 public static void checkGlide(final Player p) {
158 if (p.isGliding()) {
159 p.setGliding(false);
160 ScheduleUtils.teleport(p, p.getLocation());161 p.setFallDistance(-200);
162 if (!Settings.isBorderPushbackTakeElytra())
163 return;
52 ScheduleUtils.runAsyncTimer(new CleanKillersTask(this), Settings.getKillAbuseTime(), Settings.getKillAbuseTime(), TimeUnit.SECONDS);
53 }
54 if (Settings.getPvPDisabledFee() != 0) {
55 ScheduleUtils.runAsyncTimer(new PvPToggleFeeTask(this), 0, 1, TimeUnit.HOURS); 56 }
57
58 addOnlinePlayers();
49 this.dependencyManager = plugin.getDependencyManager();
50 this.tagTask = new TagTask(plugin.getDisplayManager());
51 if (Settings.isKillAbuseEnabled()) {
52 ScheduleUtils.runAsyncTimer(new CleanKillersTask(this), Settings.getKillAbuseTime(), Settings.getKillAbuseTime(), TimeUnit.SECONDS); 53 }
54 if (Settings.getPvPDisabledFee() != 0) {
55 ScheduleUtils.runAsyncTimer(new PvPToggleFeeTask(this), 0, 1, TimeUnit.HOURS);
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);
});