typetools / typetools/checker-framework
Confusing behavior with @CreatesMustCallFor
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
I have this class (relevant part):
@InheritableMustCall("disconnect")
public class JavaDriverClient
{
private @Owning Cluster cluster;
private @Owning Session session;
@CreatesMustCallFor
public void connect(ProtocolOptions.Compression compression) throws Exception
{
disconnect();
cluster = clusterBuilder.build();
session = cluster.connect();
}
@EnsuresCalledMethods(value = {"cluster", "session"}, methods = "close")
public void disconnect()
{
session.close();
session = null;
cluster.close();
cluster = null;
}
}
and the checker fails with the following exception:
[javac] /home/jlewandowski/dev/cassandra/c18239-static-analysis/tools/stress/src/org/apache/cassandra/stress/util/JavaDriverClient.java:203: error: [builder:required.method.not.called] @MustCall method close may not have been invoked on field session or any of its aliases.
[javac] session = cluster.connect();
[javac] ^
[javac] The type of object is: com.datastax.driver.core.Session.
[javac] Reason for going out of scope: Non-final owning field might be overwritten
It refers to the session = cluster.connect(); in connect method. It shouldn't because disconnect() was called before. However, it only allows to overwrite cluster after disconnect() and any additional owned resource cannot be overwritten.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the diagnostic from the JavaDriverClient.java example, focusing on connect(), disconnect(), and the @CreatesMustCallFor and @EnsuresCalledMethods annotations. Trace how the checker handles overwriting the session field after disconnect(), then add a regression test showing the expected behavior and verify that the erroneous builder:required.method.not.called diagnostic is resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100