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

RedundantModifier: miss violation on extra final in try-with-resources #3323

Closed
romani opened this issue Jun 28, 2016 · 1 comment
Closed
Milestone

Comments

@romani
Copy link
Member

romani commented Jun 28, 2016

/var/tmp $ cat my_check.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name = "Checker">
    <module name="TreeWalker">
        <module name="RedundantModifier"/>
    </module>
</module>

/var/tmp $ cat TestClass.java 
public class TestClass {
    public void somePublicMethod() {
        try (final FileOutputStream out = new FileOutputStream("......")) {
            //...
        }
    }
}

/var/tmp $java -jar checkstyle-7.0-all.jar -c my_check.xmlt TestClass.java 
Starting audit...
Audit done.

The final modifier is redundant in a try-with-resources, as the spec http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.20.3:

A resource declared in a ResourceSpecification is implicitly declared final (§4.12.4) if it is not explicitly declared final.

prove that it is final:

        try (FileOutputStream out = new FileOutputStream(fileName)) {
            out = new FileOutputStream(fileName); /// complication ERROR
        }
rnveach added a commit to rnveach/checkstyle that referenced this issue Jul 19, 2016
rnveach added a commit to rnveach/checkstyle that referenced this issue Jul 19, 2016
rnveach added a commit to rnveach/checkstyle that referenced this issue Jul 19, 2016
rnveach added a commit to rnveach/checkstyle that referenced this issue Jul 19, 2016
rnveach added a commit to rnveach/checkstyle that referenced this issue Jul 21, 2016
rnveach added a commit to rnveach/checkstyle that referenced this issue Jul 21, 2016
@romani romani added this to the 7.1 milestone Jul 27, 2016
@romani
Copy link
Member Author

romani commented Jul 27, 2016

fixes are merged.

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

No branches or pull requests

1 participant