An empty collection constant of raw type is used instead of its typed factory method

tx0/java:raw-empty-collectionrecommendedwarningsmell

What it finds

Collections.EMPTY_LIST, EMPTY_SET and EMPTY_MAP are raw types: whatever they are assigned to gets no type checks, and the compiler warns about it. Collections.emptyList() and its siblings return the same shared objects with the right type. The fix calls the method; it is unsafe because type inference may pick a different type in some contexts.

From the rule's source, raw_empty_collection.rs.

Example from the rule's tests
import java.util.Collections;import java.util.List; class Defaults {  List<String> names = Collections.EMPTY_LIST;tx0 reports: Collections.EMPTY_LIST has a raw type  List<String> typed = Collections.emptyList();}
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 recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:raw-empty-collection" = "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:raw-empty-collection] reason="..."

tx0 explain tx0/java:raw-empty-collection shows the same in the terminal. Found a false positive? Report it.