The OverrideBug
class has a single method, which uses a static constant:
import java.awt.Component;
import java.text.NumberFormat;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
public class OverrideBug extends DefaultListCellRenderer {
private static final NumberFormat format = NumberFormat.getCurrencyInstance();
@Override
public Component getListCellRendererComponent(
JList<?> list,
Object value, // <-- Line 13, error here
int index,
boolean isSelected,
boolean cellHasFocus
) {
if (value instanceof Double) {
value = format.format((Double) value);
}
return super.getListCellRendererComponent(
list, value, index, isSelected, cellHasFocus
);
}
}
When I compile this, the checker framework gives me an error on line 13:
[override.param] Incompatible parameter type for value.
The method I'm overriding has this signature:
public Component getListCellRendererComponent(
JList<?> list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus
)
As you can see, this perfectly matches the overriding method. The Checker Framework is objecting to overriding an Object parameter with an Object parameter!
Why am I getting this error? It makes no sense at all. And what can I do about it besides a @SuppressWarnings
annotation? I prefer to fix warnings rather than suppressing them, if possible. I especially don't like to suppress warnings that I don't understand, because I've learned through experience that this is a risky practice.
For a reproducible test case, see https://github.com/SwingGuy1024/CheckerQuestions
(When I first posted, the link didn't work, but it should work now.)