我正在尝试子类化实现AutoClosable
的类。这是一个简短的例子:
public class AutoClosableBase implements AutoCloseable {
private final int a;
public AutoClosableBase(int a) {
this.a = a;
}
@Override
public void close() throws Exception {
// nothing to do
}
}
public class AutoClosableSub extends AutoClosableBase {
private final int b;
public AutoClosableSub(int a, int b) {
super(a);
this.b = b;
}
}
然而,FindBugs(3.0.0)抱怨AutoClosableSub的构造函数,显然是因为它调用super而不关闭它:
new Sample$AutoClosableSub(Sample, int, int) may fail to clean up Sample$AutoClosableBase
Bug type OBL_UNSATISFIED_OBLIGATION (click for details)
In class Sample$AutoClosableSub
In method new Sample$AutoClosableSub(Sample, int, int)
Reference type Sample$AutoClosableBase
1 instances of obligation remaining
Obligation to clean up resource created at Sample.java:[line 27] is not discharged
Path continues at Sample.java:[line 28]
Path continues at Sample.java:[line 29]
Remaining obligations: {Sample$AutoClosableBase x 1}
我知道我可以用以下方法来压制这个:
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION")
但是,我想知道: