Skip to content
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

Resource Leak Checker suggests @Owning on a resource variable #5739

Closed
mernst opened this issue Mar 30, 2023 · 0 comments · Fixed by #5743
Closed

Resource Leak Checker suggests @Owning on a resource variable #5739

mernst opened this issue Mar 30, 2023 · 0 comments · Fixed by #5743
Assignees

Comments

@mernst
Copy link
Member

mernst commented Mar 30, 2023

Consider the following code (which is checked in as ConnectingSockets2.java):

import java.io.IOException;
import java.net.*;

class ConnectingSockets2 {

  void run(InetSocketAddress isa) {
    try (Socket serverSocket = new Socket()) {
      serverSocket.close();
      serverSocket.connect(isa);
    } catch (IOException e) {
      // do nothing
    }
  }
}

The Resource Leak Checker issues this error message:

ConnectingSockets2.java:9: error: [reset.not.owning] Calling method connect resets the must-call obligations of the expression serverSocket, which is non-owning. Either annotate its declaration with an @Owning annotation, extract it into a local variable, or write a corresponding @CreatesMustCallFor annotation on the method that encloses this statement.
      serverSocket.connect(isa);
                          ^

However, it is illegal to annotated the declaration of serverSocket as @Owning, and I think the code should be legal.

mernst added a commit that referenced this issue Mar 30, 2023
@kelloggm kelloggm self-assigned this Mar 31, 2023
wmdietl pushed a commit to eisop/checker-framework that referenced this issue Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants