You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by "Reema Taneja (JIRA)" <ji...@apache.org> on 2018/05/24 06:55:00 UTC

[jira] [Assigned] (NETBEANS-280) "Convert to try-with-resources" fix can produce erroneous code

     [ https://issues.apache.org/jira/browse/NETBEANS-280?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Reema Taneja reassigned NETBEANS-280:
-------------------------------------

    Assignee: Reema Taneja

> "Convert to try-with-resources" fix can produce erroneous code
> --------------------------------------------------------------
>
>                 Key: NETBEANS-280
>                 URL: https://issues.apache.org/jira/browse/NETBEANS-280
>             Project: NetBeans
>          Issue Type: Bug
>          Components: java - Hints
>            Reporter: Daniel Trebbien
>            Assignee: Reema Taneja
>            Priority: Major
>
> Test case:
> {code:java}
> package hintstest;
> import java.io.IOException;
> import java.io.Writer;
> import java.nio.file.Files;
> import java.nio.file.Path;
> public abstract class ConvertToTryWithResourcesTest {
>     public void test(Path path) throws IOException {
>         Writer w = Files.newBufferedWriter(path);
>         try {
>             doSomething();
>         } catch (Exception e) {
>             w.write("An exception occurred.\n");
>         } finally {
>             w.close();
>         }
>     }
>     public abstract void doSomething() throws Exception;
> }
> {code}
> Invoking the "Convert to try-with-resources" fix on {{Writer w}} produces:
> {code:java}
> package hintstest;
> import java.io.IOException;
> import java.io.Writer;
> import java.nio.file.Files;
> import java.nio.file.Path;
> public abstract class ConvertToTryWithResourcesTest {
>     public void test(Path path) throws IOException {
>         try (Writer w = Files.newBufferedWriter(path)) {
>             doSomething();
>         } catch (Exception e) {
>             w.write("An exception occurred.\n");
>         }
>     }
>     public abstract void doSomething() throws Exception;
> }
> {code}
> .. which is erroneous because {{w}}, used in the catch block, is no longer in scope.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists