aritmat / daisydiff

Automatically exported from code.google.com/p/daisydiff
0 stars 0 forks source link

InputStream, InputStreamReader and BufferReader are not closed #41

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago

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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

Attachments:

GoogleCodeExporter commented 8 years ago
Fixed in subversion r175

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