Bug 461095 - Sonar: Bad practice - Method may fail to close stream

Issue is fixed

Signed-off-by: vrubezhny <vrubezhny@exadel.com>
diff --git a/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/indexing/AddLibraryFileToIndex.java b/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/indexing/AddLibraryFileToIndex.java
index 946f2f4..88564d5 100644
--- a/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/indexing/AddLibraryFileToIndex.java
+++ b/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/indexing/AddLibraryFileToIndex.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -175,26 +175,34 @@
 					}
 					else if (org.eclipse.wst.jsdt.internal.compiler.util.Util.isArchiveFileName(file.getName())){
 						ZipFile zip = new ZipFile(file);
-						for (Enumeration e = zip.entries(); e.hasMoreElements();) {
-							if (this.isCancelled) {
-								if (JobManager.VERBOSE)
-									org.eclipse.wst.jsdt.internal.core.util.Util.verbose("-> indexing of " + zip.getName() + " has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$
-								return false;
-							}
-	
-							// iterate each entry to index it
-							ZipEntry ze = (ZipEntry) e.nextElement();
-							if (Util.isClassFileName(ze.getName())) {
-								InputStreamReader inputStreamReader = new InputStreamReader(zip.getInputStream(ze), "utf8"); //$NON-NLS-1$
-								StringBuffer buffer = new StringBuffer();
-								char c[] = new char[2048];
-								int length = 0;
-								while ((length = inputStreamReader.read(c)) > -1) {
-									buffer.append(c, 0, length);
+						try {
+							for (Enumeration e = zip.entries(); e.hasMoreElements();) {
+								if (this.isCancelled) {
+									if (JobManager.VERBOSE)
+										org.eclipse.wst.jsdt.internal.core.util.Util.verbose("-> indexing of " + zip.getName() + " has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$
+									return false;
 								}
-								JavaSearchDocument entryDocument = new JavaSearchDocument(ze, libraryFilePath, buffer.toString().toCharArray(), participant);
-								this.manager.indexDocument(entryDocument, participant, index, this.containerPath);
+		
+								// iterate each entry to index it
+								ZipEntry ze = (ZipEntry) e.nextElement();
+								if (Util.isClassFileName(ze.getName())) {
+									StringBuffer buffer = new StringBuffer();
+									InputStreamReader inputStreamReader = new InputStreamReader(zip.getInputStream(ze), "utf8"); //$NON-NLS-1$
+									try {
+										char c[] = new char[2048];
+										int length = 0;
+										while ((length = inputStreamReader.read(c)) > -1) {
+											buffer.append(c, 0, length);
+										}
+									} finally {
+										inputStreamReader.close();
+									}
+									JavaSearchDocument entryDocument = new JavaSearchDocument(ze, libraryFilePath, buffer.toString().toCharArray(), participant);
+									this.manager.indexDocument(entryDocument, participant, index, this.containerPath);
+								}
 							}
+						} finally {
+							zip.close();
 						}
 					}
 				} else {
@@ -238,7 +246,7 @@
 	{
 		try {
 			final char[] classFileChars = org.eclipse.wst.jsdt.internal.compiler.util.Util.getFileCharContent(file,null);
-			String packageName="";
+			String packageName=""; //$NON-NLS-1$
 			JavaSearchDocument entryDocument = new JavaSearchDocument(  new Path(file.getAbsolutePath()), classFileChars, participant,packageName);
 			this.manager.indexDocument(entryDocument, participant, index, this.containerPath);
 		} catch (Exception ex)
diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/corext/refactoring/changes/DeletePackageFragmentRootChange.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/corext/refactoring/changes/DeletePackageFragmentRootChange.java
index 429e150..53c9922 100644
--- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/corext/refactoring/changes/DeletePackageFragmentRootChange.java
+++ b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/corext/refactoring/changes/DeletePackageFragmentRootChange.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -154,6 +154,13 @@
 			return (int) reader.skip(Integer.MAX_VALUE);
 		} catch (IOException e) {
 			throw new CoreException(new Status(IStatus.ERROR, Corext.getPluginId(), e.getMessage(), e));
+		} finally {
+			try {
+				reader.close();
+			}
+			catch (IOException e) {
+				// Ignore
+			}
 		}
 	}
 
diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/infoviews/JavadocView.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/infoviews/JavadocView.java
index 8a36a44..e1dbc03 100644
--- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/infoviews/JavadocView.java
+++ b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/infoviews/JavadocView.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -365,15 +365,18 @@
 
 		try {
 			styleSheetURL= FileLocator.toFileURL(styleSheetURL);
-			BufferedReader reader= new BufferedReader(new InputStreamReader(styleSheetURL.openStream()));
 			StringBuffer buffer= new StringBuffer(200);
-			String line= reader.readLine();
-			while (line != null) {
-				buffer.append(line);
-				buffer.append('\n');
-				line= reader.readLine();
+			BufferedReader reader= new BufferedReader(new InputStreamReader(styleSheetURL.openStream()));
+			try {
+				String line= reader.readLine();
+				while (line != null) {
+					buffer.append(line);
+					buffer.append('\n');
+					line= reader.readLine();
+				}
+			} finally {
+				reader.close();
 			}
-
 			FontData fontData= JFaceResources.getFontRegistry().getFontData(PreferenceConstants.APPEARANCE_JAVADOC_FONT)[0];
 			return HTMLPrinter.convertTopLevelFont(buffer.toString(), fontData);
 		} catch (IOException ex) {
diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/java/AbstractJavaCompletionProposal.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
index 6e70fed..aff366a 100644
--- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
+++ b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -515,13 +515,17 @@
 			if (url != null) {
 				try {
 					url= FileLocator.toFileURL(url);
-					BufferedReader reader= new BufferedReader(new InputStreamReader(url.openStream()));
 					StringBuffer buffer= new StringBuffer(200);
-					String line= reader.readLine();
-					while (line != null) {
-						buffer.append(line);
-						buffer.append('\n');
-						line= reader.readLine();
+					BufferedReader reader= new BufferedReader(new InputStreamReader(url.openStream()));
+					try {
+						String line= reader.readLine();
+						while (line != null) {
+							buffer.append(line);
+							buffer.append('\n');
+							line= reader.readLine();
+						}
+					} finally {
+						reader.close();
 					}
 					fgCSSStyles= buffer.toString();
 				} catch (IOException ex) {
diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/java/hover/AbstractJavaEditorTextHover.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/java/hover/AbstractJavaEditorTextHover.java
index bf96fb9..eff0988 100644
--- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/java/hover/AbstractJavaEditorTextHover.java
+++ b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/java/hover/AbstractJavaEditorTextHover.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -163,13 +163,17 @@
 		if (styleSheetURL != null) {
 			try {
 				styleSheetURL= FileLocator.toFileURL(styleSheetURL);
-				BufferedReader reader= new BufferedReader(new InputStreamReader(styleSheetURL.openStream()));
 				StringBuffer buffer= new StringBuffer(200);
-				String line= reader.readLine();
-				while (line != null) {
-					buffer.append(line);
-					buffer.append('\n');
-					line= reader.readLine();
+				BufferedReader reader= new BufferedReader(new InputStreamReader(styleSheetURL.openStream()));
+				try {
+					String line= reader.readLine();
+					while (line != null) {
+						buffer.append(line);
+						buffer.append('\n');
+						line= reader.readLine();
+					}
+				} finally {
+					reader.close();
 				}
 				return buffer.toString();
 			} catch (IOException ex) {
diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/spelling/engine/AbstractSpellDictionary.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/spelling/engine/AbstractSpellDictionary.java
index 754a1d1..b5e2935 100644
--- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/spelling/engine/AbstractSpellDictionary.java
+++ b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/spelling/engine/AbstractSpellDictionary.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -487,28 +487,31 @@
 					decoder.onMalformedInput(CodingErrorAction.REPORT);
 					decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
 					final BufferedReader reader= new BufferedReader(new InputStreamReader(stream, decoder));
-					
-					boolean doRead= true;
-					while (doRead) {
-						try {
-							word= reader.readLine();
-						} catch (MalformedInputException ex) {
-							// Tell the decoder to replace malformed input in order to read the line.
-							decoder.onMalformedInput(CodingErrorAction.REPLACE);
-							decoder.reset();
-							word= reader.readLine();
-							decoder.onMalformedInput(CodingErrorAction.REPORT);
-							
-							String message= Messages.format(JavaUIMessages.AbstractSpellingDictionary_encodingError, new String[] { word, decoder.replacement(), url.toString() });
-							IStatus status= new Status(IStatus.ERROR, JavaScriptUI.ID_PLUGIN, IStatus.OK, message, ex);
-							JavaScriptPlugin.log(status);
-							
+					try {
+						boolean doRead= true;
+						while (doRead) {
+							try {
+								word= reader.readLine();
+							} catch (MalformedInputException ex) {
+								// Tell the decoder to replace malformed input in order to read the line.
+								decoder.onMalformedInput(CodingErrorAction.REPLACE);
+								decoder.reset();
+								word= reader.readLine();
+								decoder.onMalformedInput(CodingErrorAction.REPORT);
+								
+								String message= Messages.format(JavaUIMessages.AbstractSpellingDictionary_encodingError, new String[] { word, decoder.replacement(), url.toString() });
+								IStatus status= new Status(IStatus.ERROR, JavaScriptUI.ID_PLUGIN, IStatus.OK, message, ex);
+								JavaScriptPlugin.log(status);
+								
+								doRead= word != null;
+								continue;
+							}
 							doRead= word != null;
-							continue;
+							if (doRead)
+								hashWord(word);
 						}
-						doRead= word != null;
-						if (doRead)
-							hashWord(word);
+					} finally {
+						reader.close();
 					}
 					return true;
 				}
diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/spelling/engine/PersistentSpellDictionary.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/spelling/engine/PersistentSpellDictionary.java
index a25dab0..96867b6 100644
--- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/spelling/engine/PersistentSpellDictionary.java
+++ b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/text/spelling/engine/PersistentSpellDictionary.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -13,7 +13,6 @@
 
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
 import java.net.URL;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
@@ -55,20 +54,20 @@
 		if (isCorrect(word))
 			return;
 
-		OutputStreamWriter writer= null;
-		try {
-			Charset charset= Charset.forName(getEncoding());
-			ByteBuffer byteBuffer= charset.encode(word + "\n"); //$NON-NLS-1$
-			int size= byteBuffer.limit();
-			final byte[] byteArray;
-			if (byteBuffer.hasArray())
-				byteArray= byteBuffer.array();
-			else {
-				byteArray= new byte[size];
-				byteBuffer.get(byteArray);
-			}
+		Charset charset= Charset.forName(getEncoding());
+		ByteBuffer byteBuffer= charset.encode(word + "\n"); //$NON-NLS-1$
+		int size= byteBuffer.limit();
+		final byte[] byteArray;
+		if (byteBuffer.hasArray())
+			byteArray= byteBuffer.array();
+		else {
+			byteArray= new byte[size];
+			byteBuffer.get(byteArray);
+		}
+		FileOutputStream fileStream = null;
 			
-			FileOutputStream fileStream= new FileOutputStream(fLocation.getPath(), true);
+		try {
+			fileStream= new FileOutputStream(fLocation.getPath(), true);
 			
 			// Encoding UTF-16 charset writes a BOM. In which case we need to cut it away if the file isn't empty
 			int bomCutSize= 0;
@@ -81,9 +80,10 @@
 			return;
 		} finally {
 			try {
-				if (writer != null)
-					writer.close();
+				if (fileStream != null)
+					fileStream.close();
 			} catch (IOException e) {
+				// Ignore
 			}
 		}
 
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/util/Util.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/util/Util.java
index 82079b8..9fe4763 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/util/Util.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/util/Util.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -49,7 +49,7 @@
 import org.eclipse.wst.jsdt.internal.compiler.problem.DefaultProblem;
 import org.eclipse.wst.jsdt.internal.compiler.problem.DefaultProblemFactory;
 public class Util {
-	private static String TARGET_PLUGIN="org.eclipse.wst.jsdt.core";
+	private static String TARGET_PLUGIN="org.eclipse.wst.jsdt.core"; //$NON-NLS-1$
 	// Trace for delete operation
 	/*
 	 * Maximum time wasted repeating delete operations while running JDT/Core tests.
@@ -1247,21 +1247,17 @@
 }
 public static void writeToFile(String contents, String destinationFilePath) {
 	File destFile = new File(destinationFilePath);
-	FileOutputStream output = null;
+	PrintWriter writer = null;
 	try {
-		output = new FileOutputStream(destFile);
-		PrintWriter writer = new PrintWriter(output);
+		writer = new PrintWriter(new FileOutputStream(destFile));
 		writer.print(contents);
 		writer.flush();
 	} catch (IOException e) {
 		e.printStackTrace();
 		return;
 	} finally {
-		if (output != null) {
-			try {
-				output.close();
-			} catch (IOException e2) {
-			}
+		if (writer != null) {
+			writer.close();
 		}
 	}
 }
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/utils/BundleResourceUtil.java b/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/utils/BundleResourceUtil.java
index 5e954c6..e007ada 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/utils/BundleResourceUtil.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/utils/BundleResourceUtil.java
@@ -1,5 +1,5 @@
 /*******************************************************************************

- * Copyright (c) 2005, 2012 IBM Corporation and others.

+ * Copyright (c) 2005, 2015 IBM Corporation and others.

  * All rights reserved. This program and the accompanying materials

  * are made available under the terms of the Eclipse Public License v1.0

  * which accompanies this distribution, and is available at

@@ -137,9 +137,10 @@
 				IFile file = null;

 				URL entry = Activator.getDefault().getBundle().getEntry(zipFileEntry);

 				if(entry != null) {

+					ZipInputStream input = null;

 					try {

 						byte[] b = new byte[2048];

-						ZipInputStream input = new ZipInputStream(entry.openStream());

+						input = new ZipInputStream(entry.openStream());

 

 						ZipEntry nextEntry = input.getNextEntry();

 						while(nextEntry != null) {

@@ -185,6 +186,14 @@
 					} catch(CoreException e) {

 						// TODO Auto-generated catch block

 						e.printStackTrace();

+					} finally {

+						try {

+							if (input != null)

+								input.close();

+						}

+						catch (IOException e) {

+							// Ignore

+						}

 					}

 				} else {

 					System.err.println("can't find " + zipFileEntry);

diff --git a/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/utils/SequenceReaderTests.java b/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/utils/SequenceReaderTests.java
index 7363eda..baabfa1 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/utils/SequenceReaderTests.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/utils/SequenceReaderTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************

- * Copyright (c) 2009 IBM Corporation and others.

+ * Copyright (c) 2015 IBM Corporation and others.

  * All rights reserved. This program and the accompanying materials

  * are made available under the terms of the Eclipse Public License v1.0

  * which accompanies this distribution, and is available at

@@ -25,10 +25,14 @@
 		Reader[] readers = new Reader[]{new StringReader("Ready")};

 		Reader sequenceReader = new SequenceReader(readers);

 		StringBuffer buff = new StringBuffer();

-		int c = sequenceReader.read();

-		while (c != -1) {

-			buff.append((char) c);

-			c = sequenceReader.read();

+		try {

+			int c = sequenceReader.read();

+			while (c != -1) {

+				buff.append((char) c);

+				c = sequenceReader.read();

+			}

+		} finally {

+			sequenceReader.close();

 		}

 		assertEquals("Ready", buff.toString());

 	}

@@ -37,10 +41,14 @@
 		Reader[] readers = new Reader[]{new StringReader("Ready"), new StringReader("Set"), new StringReader("Go")};

 		Reader sequenceReader = new SequenceReader(readers);

 		StringBuffer buff = new StringBuffer();

-		int c = sequenceReader.read();

-		while (c != -1) {

-			buff.append((char) c);

-			c = sequenceReader.read();

+		try {

+			int c = sequenceReader.read();

+			while (c != -1) {

+				buff.append((char) c);

+				c = sequenceReader.read();

+			}

+		} finally {

+			sequenceReader.close();

 		}

 		assertEquals("ReadySetGo", buff.toString());

 	}

@@ -49,10 +57,14 @@
 		Reader[] readers = new Reader[]{new StringReader("")};

 		Reader sequenceReader = new SequenceReader(readers);

 		StringBuffer buff = new StringBuffer();

-		int c = sequenceReader.read();

-		while (c != -1) {

-			buff.append((char) c);

-			c = sequenceReader.read();

+		try {

+			int c = sequenceReader.read();

+			while (c != -1) {

+				buff.append((char) c);

+				c = sequenceReader.read();

+			}

+		} finally {

+			sequenceReader.close();

 		}

 		assertEquals("something was read from an empty reader", 0, buff.length());

 	}

@@ -61,10 +73,14 @@
 		Reader[] readers = new Reader[0];

 		Reader sequenceReader = new SequenceReader(readers);

 		StringBuffer buff = new StringBuffer();

-		int c = sequenceReader.read();

-		while (c != -1) {

-			buff.append((char) c);

-			c = sequenceReader.read();

+		try {

+			int c = sequenceReader.read();

+			while (c != -1) {

+				buff.append((char) c);

+				c = sequenceReader.read();

+			}

+		} finally {

+			sequenceReader.close();

 		}

 		assertEquals("something was read from nothing", 0, buff.length());

 	}

@@ -73,10 +89,14 @@
 		Reader[] readers = new Reader[]{new StringReader("Ready"), new StringReader("Set"), new StringReader("Go")};

 		Reader sequenceReader = new BufferedReader(new SequenceReader(readers));

 		StringBuffer buff = new StringBuffer();

-		int c = sequenceReader.read();

-		while (c != -1) {

-			buff.append((char) c);

-			c = sequenceReader.read();

+		try {

+			int c = sequenceReader.read();

+			while (c != -1) {

+				buff.append((char) c);

+				c = sequenceReader.read();

+			}

+		} finally {

+			sequenceReader.close();

 		}

 		assertEquals("ReadySetGo", buff.toString());

 	}

diff --git a/tests/org.eclipse.wst.jsdt.ui.tests/src/org/eclipse/wst/jsdt/ui/tests/utils/BundleResourceUtil.java b/tests/org.eclipse.wst.jsdt.ui.tests/src/org/eclipse/wst/jsdt/ui/tests/utils/BundleResourceUtil.java
index 554f515..304dbd8 100644
--- a/tests/org.eclipse.wst.jsdt.ui.tests/src/org/eclipse/wst/jsdt/ui/tests/utils/BundleResourceUtil.java
+++ b/tests/org.eclipse.wst.jsdt.ui.tests/src/org/eclipse/wst/jsdt/ui/tests/utils/BundleResourceUtil.java
@@ -1,5 +1,5 @@
 /*******************************************************************************

- * Copyright (c) 2005, 2012 IBM Corporation and others.

+ * Copyright (c) 2005, 2015 IBM Corporation and others.

  * All rights reserved. This program and the accompanying materials

  * are made available under the terms of the Eclipse Public License v1.0

  * which accompanies this distribution, and is available at

@@ -138,9 +138,10 @@
 				IFile file = null;

 				URL entry = Activator.getDefault().getBundle().getEntry(zipFileEntry);

 				if(entry != null) {

+					ZipInputStream input = null;

 					try {

 						byte[] b = new byte[2048];

-						ZipInputStream input = new ZipInputStream(entry.openStream());

+						input = new ZipInputStream(entry.openStream());

 

 						ZipEntry nextEntry = input.getNextEntry();

 						while(nextEntry != null) {

@@ -186,6 +187,14 @@
 					} catch(CoreException e) {

 						// TODO Auto-generated catch block

 						e.printStackTrace();

+					} finally {

+						try {

+							if (input != null)

+								input.close();

+						}

+						catch (IOException e) {

+							// Ignore

+						}

 					}

 				} else {

 					System.err.println("can't find " + zipFileEntry);