This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 197883 - Convert to try-with-resources only picks up one resource
Summary: Convert to try-with-resources only picks up one resource
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.0
Hardware: PC Windows 7 x64
: P4 normal (vote)
Assignee: Tomas Zezula
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-20 04:33 UTC by MauveCloud
Modified: 2016-07-07 07:18 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description MauveCloud 2011-04-20 04:33:53 UTC
I created the following snippet of code to demonstrate this:
public static void main(final String[] args) throws IOException {
    final char[] buffer = new char[100];
    final FileReader reader = new FileReader("test.txt");
    final FileWriter writer = new FileWriter("test2.txt");
    reader.read(buffer);
    writer.write(buffer);
    writer.close();
    reader.close();
}

Using the available "Convert to try-with-resources" gives me the following:
public static void main(final String[] args) throws IOException {
    final char[] buffer = new char[100];
    try (FileReader reader = new FileReader("test.txt")) {
        final FileWriter writer = new FileWriter("test2.txt");
        reader.read(buffer);
        writer.write(buffer);
        writer.close();
    }
}

However, since the Java 7 try-with-resources statement allows more than one resource, it should be able to give me this:
public static void main(final String[] args) throws IOException {
    final char[] buffer = new char[100];
    try (FileReader reader = new FileReader("test.txt"); FileWriter writer = new FileWriter("test2.txt");) {
        reader.read(buffer);
        writer.write(buffer);
    }
}
Comment 1 MauveCloud 2011-04-20 04:36:45 UTC
Update: shortly after writing up this bug, I noticed that it gave me the hint again on the FileWriter, and using that added it to the list of resources for the try block, but it should have been able to use both with one such hint.
Comment 2 Jan Lahoda 2011-05-04 09:31:10 UTC
Feel free to reassign back.
Comment 3 Tomas Zezula 2011-05-04 18:08:01 UTC
As described in comment #1 it's possible to do it by another invocation of the hint.
Yes, it can be done that all these hints are invoked at once (requires either a new item in the hint or option).
Comment 4 Martin Balin 2016-07-07 07:18:48 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss