A method that reports failure through its result is called and the result is dropped
What it finds
file.delete(); returns false when the file could not be deleted, and does not throw; dropping the result hides the failure. The same holds for mkdir, mkdirs, createNewFile, renameTo and the permission setters of File, for tryLock of a lock, tryAcquire of a semaphore, and the waits with a time limit, which return whether they finished in time.
Reported is a statement that only calls one of these methods: the File methods on a variable or instance creation of java.io.File, tryLock and tryAcquire on any receiver, and await or awaitTermination with a time limit.
From the rule's source, ignored_status_result.rs.
import java.io.File;import java.util.concurrent.TimeUnit;import java.util.concurrent.locks.Lock; class Files { void clean(File dir, Lock lock, java.util.concurrent.CountDownLatch latch) throws Exception { dir.delete();tx0 reports: delete reports failure through its result new File("x").mkdirs();tx0 reports: mkdirs reports failure lock.tryLock();tx0 reports: tryLock reports failure latch.await(1, TimeUnit.SECONDS);tx0 reports: await reports failure boolean ok = dir.delete(); latch.await(); }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:ignored-status-result" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:ignored-status-result] reason="..."tx0 explain tx0/java:ignored-status-result shows the same in the terminal. Found a false positive? Report it.