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

False positive in CheckedExceptionNotThrown with short-form try-with-resources #3321

Closed
ksobolew opened this issue Jul 13, 2022 · 1 comment

Comments

@ksobolew
Copy link

Say I have a method like this:

    private final AutoCloseable afterClassCloser = ...;

    @AfterClass(alwaysRun = true)
    public final void close()
            throws Exception
    {
        try (afterClassCloser) {
            cleanupAndStuff();
        }
    }

Then CheckedExceptionNotThrown will report that the Exception is not thrown, even though it can be thrown by afterClassCloser::close.

If I change it to:

        try (AutoCloseable ignored = afterClassCloser) {
            cleanupAndStuff();
        }

then there is no error.

@graememorgan
Copy link
Member

Thanks for the report, that's a nice one! I've never seen the assignment-free try-with-resources syntax. Looks like it's "new" in Java 9.

copybara-service bot pushed a commit that referenced this issue Aug 1, 2022
copybara-service bot pushed a commit that referenced this issue Aug 1, 2022
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