A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2650 below:

[java] UseTryWithResources false positive when AutoCloseable helper used · Issue #2650 · pmd/pmd · GitHub

Affects PMD Version:

maven-pmd-plugin 3.13.0 (pmd 6.21.0)

Rule: UseTryWithResources

Description:

PMD Failure: UseTryWithResources when resource is not AutoCloseable and closed via external class which implement AutoCloseable

Code Sample demonstrating the issue:

public class PMDUseTryWithResources {

    static class ResourceCloser implements AutoCloseable {
        public static void close(NotAutoCloseable notAutoCloseable) {
            notAutoCloseable.close();
        }

        @Override
        public void close() throws Exception {
            // nothing
        }
    }

    interface NotAutoCloseable {
        void close();
    }

    public void useTryWithResources() {
        NotAutoCloseable notAutoCloseable = null;
        try {
            notAutoCloseable = new NotAutoCloseable() {
                @Override
                public void close() {
                }
            };
        } finally {
            if (notAutoCloseable != null) {
                ResourceCloser.close(notAutoCloseable);
            }
        }
    }
}

Steps to reproduce:

  1. mvn install

Running PMD through: Maven


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4