CADbloke / daisydiff

Automatically exported from code.google.com/p/daisydiff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

InputStream, InputStreamReader and BufferReader are not closed

GoogleCodeExporter opened this issue · comments

I have a resource locking problem. The Streams that are opened by the Main 
Class are not closed by the application.

Line 99 => InputStream oldStream, newStream;
Line 167-169 =>  BufferedReader and InputStreamReader




Original issue reported on code.google.com by firecree...@gmail.com on 24 Feb 2012 at 9:58

Original comment by kkape...@gmail.com on 24 Feb 2012 at 11:53

  • Changed state: Accepted
  • Added labels: ****
  • Removed labels: ****
If the streams are closed properly the issue goes away?
Have you already fixed it yourself? Do you have a patch?

Original comment by kkape...@gmail.com on 24 Feb 2012 at 3:45

  • Changed state: Started
  • Added labels: ****
  • Removed labels: ****
I move the initialization of oldStream and newStream object outside the 
try->catch->block

....
String[] css = new String[]{};

InputStream oldStream = null;
InputStream newStream = null;
....

and add a finally block

finally {
            try {
                if(oldStream != null) oldStream.close();
            } catch (IOException e) {
                //ignore this exception
            }
            try {
                if(newStream != null) newStream.close();
            } catch (IOException e) {
                //ignore this exception
            }
        }

furthermore it would be helpful to rewrite Line 167-169

InputStreamReader oldReader = null;
                BufferedReader oldBuffer = null;

                InputStreamReader newISReader = null;
                BufferedReader newBuffer = null;
                try {
                    oldReader = new InputStreamReader(oldStream);
                    oldBuffer = new BufferedReader(oldReader);

                    newISReader = new InputStreamReader(newStream);
                    newBuffer = new BufferedReader(newISReader);
                    DaisyDiff.diffTag(oldBuffer, newBuffer, postProcess);

                } catch (Exception e) {
                    System.out.println(e);
                } finally {
                    oldBuffer.close();
                    newBuffer.close();
                    oldReader.close();
                    newISReader.close();
                }


Original comment by firecree...@gmail.com on 24 Feb 2012 at 11:33

  • Added labels: ****
  • Removed labels: ****
Can you perform a diff on your code to create a patch and post it here? I will 
apply it to trunk after testing.

Original comment by kkape...@gmail.com on 25 Feb 2012 at 9:39

  • Added labels: ****
  • Removed labels: ****
A local test shows, that this will prevent a resource blocking problem.

Original comment by firecree...@gmail.com on 27 Feb 2012 at 4:41

  • Added labels: ****
  • Removed labels: ****

Attachments:

Fixed in subversion r175

Original comment by kkape...@gmail.com on 27 Feb 2012 at 8:59

  • Changed state: Fixed
  • Added labels: ****
  • Removed labels: ****