Search code examples
javainterfaceprivate-methodsspotbugs

Uncalled private method in an interface


I have an interface with a default method and a private method, where the private method is called from the default method.

When running Spotbugs, it issues an error that the private method is never called: UPM_UNCALLED_PRIVATE_METHOD.

public interface Foo {

    default boolean foo(int value1, int value2) {
        return bar(value1 + value2);
    }

    private boolean bar(int value) {
        return value == 0;
    }

}

I'm doing something wrong or it's a Spotbugs issue?

Note 1: When modifying the private method to static, it doesn't report the error.

Note 2: I've seen similar issues reported, but all are closed and related to class instead of interface.


UPDATE

A similar issue was recently reported on Github (#1988), but hasn't been solved yet.


Solution

  • Spotbugs 4.5.3 reports this as "low priority" bug.

    IMHO you have basically two options:

    The solution with the annotation is probably easier to implement but clutters your source code.

    The solution with the filter file might be harder to implement (if you do not use a filter file already) and the connection between the actual code and the filter might get lost, but your source code is not cluttered with annotations just to mute a noisy tool.