Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » New (unexpected) warning with Juno 4.2 RC2
New (unexpected) warning with Juno 4.2 RC2 [message #877355] Sat, 26 May 2012 14:37 Go to next message
Bernard SARTER is currently offline Bernard SARTERFriend
Messages: 76
Registered: August 2011
Location: Paris, France
Member
Hello,

I have a Java 7 code, that compiles without any warnings with Eclipse Indigo 3.7.2.

When trying to move to Eclipse Juno 4.2RC2, I get a warning that I don't understand.

Here my code sample:

try (InputStreamReader socketIn = new InputStreamReader(fSocket.getInputStream())) {
   while (isConnected()) {
      int k = socketIn.read(charData);
      ...
   }
} catch (IOException e) {
   ...
}


The warning is "Resource leak: socketIn is never closed"

(my understanding was that Java 7 will ensure that the resource will be closed outside the try / catch block.)

Installed JRE: Java 1.7_u4 (from Oracle, on a Win 7 PC).

Any idea ?

Thanks,
Bernard.
Re: New (unexpected) warning with Juno 4.2 RC2 [message #877369 is a reply to message #877355] Sat, 26 May 2012 15:14 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1034
Registered: July 2009
Senior Member
Hi Bernard,

This looks like a bug. Using just the lines you quoted doesn't seem to suffice for reproducing.
Could you please check the code you omitted and compare against existing bugs like:
- https://bugs.eclipse.org/bugs/show_bug.cgi?id=371614
- https://bugs.eclipse.org/bugs/show_bug.cgi?id=360910

If your code looks different please file a new bug with sufficient code for reproducing.

Thanks,
Stephan
Re: New (unexpected) warning with Juno 4.2 RC2 [message #877390 is a reply to message #877369] Sat, 26 May 2012 16:35 Go to previous messageGo to next message
Bernard SARTER is currently offline Bernard SARTERFriend
Messages: 76
Registered: August 2011
Location: Paris, France
Member
Hi,

Thanks for your quick reply.

I have the feeling that it is the same bug as bug_id=371614, but just in case, here is a full snippet that shows the warning:

The warning disappears if I remove the "while (true)" line.

package p;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class myClass implements Runnable {

    private Socket fSocket;

    public synchronized void connect() throws IOException {
        fSocket = new Socket("localhost", 12345);
    }

    public void run() {
        try (InputStreamReader socketIn = new InputStreamReader(fSocket.getInputStream())) {

            while (true) {
                if (socketIn.read(new char[1024]) < 0)
                    throw new IOException("Error");
            }
           
        } catch (IOException e) {
        }
    }    
}


Regards,
Bernard.
Re: New (unexpected) warning with Juno 4.2 RC2 [message #877431 is a reply to message #877390] Sat, 26 May 2012 18:03 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1034
Registered: July 2009
Senior Member
Thanks for the example,
I can reproduce now and will follow up in bug 371614 (for 4.3, maybe 4.2.1).

Stephan
Previous Topic:Errors in setting up JSF in a dynamic web module.
Next Topic:creating new eclipse project using APIs getting error when using same workspace
Goto Forum:
  


Current Time: Sun Nov 23 01:04:38 GMT 2014

Powered by FUDForum. Page generated in 0.02325 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software