A MessageDigest is kept in an instance field, so concurrent calls on the same object mix their input

tx0/java:digest-in-fieldstrictwarningreliability/logicdepth fastbug

What it finds

A MessageDigest accumulates input between update and digest. Kept in a field of an object used from several threads, two hashes in progress corrupt each other. A new digest per call, or one per thread, keeps them apart.

Reported is an instance field declared as MessageDigest.

From the rule's source, digest_in_field.rs.

Example from the rule's tests
import java.security.MessageDigest; class Hasher {  private MessageDigest digest;tx0 reports: mix their input  private static final String NAME = "SHA-256";}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:digest-in-field" = "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:digest-in-field] reason="..."

tx0 explain tx0/java:digest-in-field shows the same in the terminal. Found a false positive? Report it.