Link to home
Start Free TrialLog in
Avatar of onaled777
onaled777Flag for United States of America

asked on

Potential Resource Leak Error in Eclipse

I changed some lines  in my code from:

                                InputStream pdfInputStream = pdDoc.getContentStream().getStream();
				byte[] tiffFile = IOUtils.toByteArray(pdfInputStream);
					pdfInputStream.close();

Open in new window


to

					byte[] tiffFile = IOUtils.toByteArray(pdDoc.getContentStream().getStream());
					pdDoc.getContentStream().getStream().close();

Open in new window


I notice that got rid of a 'Potential Resource Leak Error' that was being thrown by eclipse.

(Note: Right now my eclipse is configured to throw  an error whenever such issues arise)

My questions are:
1) Why does that change correct the error?
2) When written as in the second code snippet, is it best practice to add the following snippet in the finally block?

		}finally{
			if (pdDoc.getContentStream().getStream()!=null) {
				pdDoc.getContentStream().getStream().close();
			}
		}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of onaled777

ASKER

Thanks Krakatoa.  Apparently the issue was due to the specifications in COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE on which the Potential Resource Leak Error is Based.
Ah - you found that from the vendor presumably. Anyway, glad to hear 'fixed'.