Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

checker framework: Supress Warnings in default constructor

I have two constructors: normal ctor which initialises the object properly and a second default ctor for Hibernate which generates initialize fields warnings. What's the preferred way to get rid of the warnings?

package test;

public class Example {
    String x;

    public Example(String x) {
        this.x = x;
    }

    Example() {
        // Ctor for Hibernate, warnings generated here.
    }
}
like image 339
Keith Whittingham Avatar asked Feb 26 '26 02:02

Keith Whittingham


1 Answers

You didn't mention looking in the documentation, so I'm not sure whether you have done so. The Checker Framework manual contains a chapter titled "Suppressing warnings", which might contain all the information you need.

The most common approach is to write a @SuppressingWarnings annotation, which is the standard way to suppress warnings from the Java compiler.

You should write it on the smallest program element possible (such as a local variable declaration rather than the whole constructor or class), and you should supply the most specific key possible. The reason is to avoid accidentally suppressing more warnings than you intended.

like image 118
mernst Avatar answered Mar 01 '26 11:03

mernst



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!