-
Notifications
You must be signed in to change notification settings - Fork 380
Closed
Closed
Copy link
Labels
Description
Given this code:
import java.io.*;
import org.checkerframework.checker.nullness.qual.*;
import org.checkerframework.checker.mustcall.qual.*;
import org.checkerframework.checker.calledmethods.qual.*;
abstract class TestCase {
abstract @Nullable Closeable alloc();
abstract boolean arbitraryChoice();
void method() throws IOException {
if (arbitraryChoice()) {
return;
}
Closeable r1 = alloc();
if (r1 == null) {
return;
}
r1.close();
}
}
The RLC reports
error: [required.method.not.called] @MustCall method close may not have been invoked on r1 or any of its aliases.
Closeable r1 = alloc();
^
The type of object is: java.io.Closeable.
Reason for going out of scope: regular method exit
The error looks spurious. Indeed, removing the early return block
if (arbitraryChoice()) {
return;
}
silences the warning! It appears that the RLC wants us to close r1
at the premature return site, before it has been defined.