-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected required.method.not.called
when implementing a resources collection/map
#6054
Comments
@msridhar do you think it is possible to fix it for the upcoming release? Or maybe you can suggest some workaround? I'm sorry, I know that Apache Cassandra is a demanding project for this kind of tools but we believe your tool will help use significantly improve the code :) |
Hi @jacek-lewandowski, I took a look at this example. I don't think it indicates a bug in the checker per se: rather, I think the issue here is that the error message was confusing. The confusing-ness of the error message was in turn caused by the use of Here is a version of the program that compiles with no warnings on I want to draw your attention to the most important change: I've replaced or removed all of the
|
No need to apologize; we are really excited that the Resource Leak Checker could be useful for an important project like Cassandra! Please keep filing issues and letting us know pain points, and we will address them as soon as we can. |
Do the confusing error messages have the same root cause as #4947? It'd be great if we could somehow improve those. |
Also, while the checker may not report any warnings for @kelloggm's updated example, I'm not sure it is verifying the intended property. In particular:
|
Yes.
The warning about this is the one that I suppressed: the checker is not actually verifying anything about the |
Thanks for looking into that. I must say I'm confused - the documentation says explicitly that it can be OR:
We have a kind of a transaction-like object with different methods to commit or to discard. Therefore we expect either one or another method is called. |
The trick with |
Sorry that this documentation is a bit confusing. Let me explain further (and if this is helpful in clarifying what
The checker doesn't currently have a way to express "this variable has a single must-call obligation, but that obligation can be satisfied by calling either
The key difference is that |
Let me say that my words: @MustCall({"a", "b"})
class Test {
void a();
void b();
void c();
}
@MustCall({"a"}) t = new Test(); // correct
@MustCall({"b"}) t = new Test(); // correct
@MustCall({"a", "b"}) t = new Test(); // correct
@MustCall({}) t = new Test(); // correct
@MustCall({"c"}) t = new Test(); // wrong And the same pattern applies to subclasses. Do I understand that correctly?
Yes, our use case is that we expect either one or another method is called. I have some idea you may consider - instead of pointing to the exact method name that must be called, let the user point to the user-defined or some predefined annotation - that is, must-call obligation would refer to any method annotated with that annotation. In our case it could look like this: @MustCall({CloseMethod.class})
class Transaction {
@CloseMethod
void commit();
@CloseMethod
void abort();
} Also, that approach would make project refactorings safer as the CheckerFramework would not need to base on quoted method names. WDYT?
Got it, thanks for explanation!
All those explanation are very useful to me, I fully support adding those notes to the docs :) |
I think this is reversed. You can see a figure depicting https://checkerframework.org/manual/#must-call-annotations Basically, if A is a superset of B, then you can assign a value of type @MustCall({"a"}) t = new Test(); // wrong
@MustCall({"b"}) t = new Test(); // wrong
@MustCall({"a", "b"}) t = new Test(); // correct
@MustCall({}) t = new Test(); // wrong
@MustCall({"c"}) t = new Test(); // wrong
@MustCall({"a,b,c"}) t = new Test(); // correct
I really like this idea! It's useful for a couple of reasons. First, it gives a possible workaround for the issue we currently have with method overloading (if there was a case where only one of the overloads serves as the
Sure, we will work on this! FYI, a couple of us are fairly busy with other obligations through the month of July; we should have more cycles in early August to work on triaging and fixing all these issues. We are very grateful for all the reports. |
So I was trying to implement a resources map to be used to such situations, I have this:
which is used in the following way:
where the
FlushWriter
is something like:Now, when I try to check it, it complains with the following:
I'm not sure what I'm doing wrong there?
The text was updated successfully, but these errors were encountered: