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

Why we need to add @EnsuresCalledMethods for resource.close even if resource.close is the only call in the method? #6039

Closed
jacek-lewandowski opened this issue Jun 16, 2023 · 1 comment

Comments

@jacek-lewandowski
Copy link

Unless close is explicitly annotated with @EnsuresCalledMethods("this.resource", "close"), the analyser complains with required.method.not.called on the resource declaration.

    @Owning InputStream resource;

    public void close()
    {
        resources.close();
    }

Is it a bug or expected behaviour?

@kelloggm
Copy link
Contributor

Is it a bug or expected behaviour?

This is expected behavior. The analysis is modular, meaning that it only analyzes each program element once. When analyzing element A (in this case, the field resource), the analysis is therefore only able to use the signature of some other element B (in this case, the method close()): it is not able to introspect into close() to see that it calls resources.close(). The @EnsuresCalledMethods annotation makes this information visible outside the method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants