Index: deployment/src/main/org/jboss/deployment/services/DeploymentManagerService.java
===================================================================
--- deployment/src/main/org/jboss/deployment/services/DeploymentManagerService.java	(revision 113831)
+++ deployment/src/main/org/jboss/deployment/services/DeploymentManagerService.java	(working copy)
@@ -270,25 +270,46 @@
       {
          if (parentFile.mkdirs() == false)
             throw new IOException("Failed to create local path: " + parentFile);
-      }
+      } 
 
       InputStream is = moduleID.getContentIS();
       if( is == null )
       {
          is = deployURL.openStream();
       }
-      BufferedInputStream bis = new BufferedInputStream(is);
-      byte[] buffer = new byte[4096];
-      FileOutputStream fos = new FileOutputStream(deployFile);
-      BufferedOutputStream bos = new BufferedOutputStream(fos);
-      int count = 0;
-      while ((count = bis.read(buffer)) > 0)
-      {
-         bos.write(buffer, 0, count);
+      BufferedOutputStream bos = null;
+      BufferedInputStream bis = null;
+      try{
+          bis = new BufferedInputStream(is);
+          byte[] buffer = new byte[4096];
+          FileOutputStream fos = new FileOutputStream(deployFile);
+          bos = new BufferedOutputStream(fos);
+          int count = 0;
+          while ((count = bis.read(buffer)) > 0)
+          {
+             bos.write(buffer, 0, count);
+          }
+      }finally{
+          try{
+              if(bis!=null)
+                  bis.close();
+          }catch(IOException e){
+          }
+          
+          try{
+              if(is!=null)
+                  is.close();
+          }catch(IOException e){
+          }
+          
+          try{
+              if(bos!=null)
+                  bos.close();
+          }catch(IOException e){
+          }
+          
+          
       }
-      bis.close();
-      bos.close();
-
       moduleMap.put(url, moduleID);
 
       // TODO: arrange deploy_phase2 (and TC glue code).
Index: deployment/src/main/org/jboss/deployment/spi/LocalhostTarget.java
===================================================================
--- deployment/src/main/org/jboss/deployment/spi/LocalhostTarget.java	(revision 113831)
+++ deployment/src/main/org/jboss/deployment/spi/LocalhostTarget.java	(working copy)
@@ -105,21 +105,19 @@
       }
       finally
       {
-         try
-         {
+
             if (outs != null)
             {
-               outs.close();
+                try{
+                    outs.close();
+                }catch(IOException e){}
             }
             if (ins != null)
             {
-               ins.close();
+                try{
+                    ins.close();
+                }catch(IOException e){}
             }
-         }
-         catch (IOException e)
-         {
-            // ignore this one            
-         }
       }
    }
 
Index: deployment/src/main/org/jboss/deployment/spi/configurations/WarConfiguration.java
===================================================================
--- deployment/src/main/org/jboss/deployment/spi/configurations/WarConfiguration.java	(revision 113831)
+++ deployment/src/main/org/jboss/deployment/spi/configurations/WarConfiguration.java	(working copy)
@@ -22,6 +22,7 @@
 package org.jboss.deployment.spi.configurations;
 
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.HashMap;
@@ -129,11 +130,18 @@
          String metaStr = metaData.toXMLString();
          JarUtils.addJarEntry(jos, DeploymentMetaData.ENTRY_NAME, new ByteArrayInputStream(metaStr.getBytes()));
          jos.flush();
-         jos.close();
+         
       }
       catch (Exception e)
       {
          System.out.println("config IO exception error: " + e.getMessage());
+      } finally{
+          try {
+            jos.close();
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
       }
    }
 
Index: deployment/src/main/org/jboss/deployment/spi/DeploymentManagerImpl.java
===================================================================
--- deployment/src/main/org/jboss/deployment/spi/DeploymentManagerImpl.java	(revision 113831)
+++ deployment/src/main/org/jboss/deployment/spi/DeploymentManagerImpl.java	(working copy)
@@ -464,89 +464,113 @@
       File tmpFile = File.createTempFile("jboss_deployment_", ".zip");
       log.debug("temporary deployment file: " + tmpFile);
 
-      JarInputStream jis = new JarInputStream(moduleArchive);
-
-      // make sure we don't loose the manifest when creating a new JarOutputStream
+      JarInputStream jis = null;
       JarOutputStream jos = null;
-      FileOutputStream fos = new FileOutputStream(tmpFile);
-      Manifest manifest = jis.getManifest();
-      if (manifest != null)
-         jos = new JarOutputStream(fos, manifest);
-      else jos = new JarOutputStream(fos);
-
-      // process all modules
-      TargetModuleInfo moduleInfo = new TargetModuleInfo();
-      ModuleType moduleType = null;
-      JarEntry entry = jis.getNextJarEntry();
-      while (entry != null)
-      {
-         String entryName = entry.getName();
-
-         // only process file entries
-         if (entryName.endsWith("/") == false)
-         {
-            if (entryName.endsWith("/application.xml"))
-            {
-               moduleType = ModuleType.EAR;
-            }
-            else if (entryName.endsWith("/application-client.xml"))
-            {
-               moduleType = ModuleType.CAR;
-            }
-            else if (entryName.endsWith("/ra.xml"))
-            {
-               moduleType = ModuleType.RAR;
-            }
-            else if (entryName.endsWith("/web.xml"))
-            {
-               moduleType = ModuleType.WAR;
-            }
-            else if (entryName.endsWith("/ejb-jar.xml"))
-            {
-               moduleType = ModuleType.EJB;
-            }
-
-            // process a sub module
-            if (entryName.endsWith(".jar") || entryName.endsWith(".war"))
-            {
-               File tmpSubModule = processSubModule(entryName, jis);
-               FileInputStream fis = new FileInputStream(tmpSubModule);
-               JarUtils.addJarEntry(jos, entryName, fis);
-               fis.close();
-            }
-            else
-            {
-               if (mapDeploymentPlan.get("!/" + entryName) == null)
-                  JarUtils.addJarEntry(jos, entryName, jis);
-               else log.debug("Skip entry found in deployment plan: " + entryName);
-            }
-         }
-
-         entry = jis.getNextJarEntry();
+      FileOutputStream fos = null;
+      try{
+          jis = new JarInputStream(moduleArchive);
+          // make sure we don't loose the manifest when creating a new JarOutputStream
+          
+          fos = new FileOutputStream(tmpFile);
+          Manifest manifest = jis.getManifest();
+          if (manifest != null)
+             jos = new JarOutputStream(fos, manifest);
+          else jos = new JarOutputStream(fos);
+    
+          // process all modules
+          TargetModuleInfo moduleInfo = new TargetModuleInfo();
+          ModuleType moduleType = null;
+          JarEntry entry = jis.getNextJarEntry();
+          while (entry != null)
+          {
+             String entryName = entry.getName();
+    
+             // only process file entries
+             if (entryName.endsWith("/") == false)
+             {
+                if (entryName.endsWith("/application.xml"))
+                {
+                   moduleType = ModuleType.EAR;
+                }
+                else if (entryName.endsWith("/application-client.xml"))
+                {
+                   moduleType = ModuleType.CAR;
+                }
+                else if (entryName.endsWith("/ra.xml"))
+                {
+                   moduleType = ModuleType.RAR;
+                }
+                else if (entryName.endsWith("/web.xml"))
+                {
+                   moduleType = ModuleType.WAR;
+                }
+                else if (entryName.endsWith("/ejb-jar.xml"))
+                {
+                   moduleType = ModuleType.EJB;
+                }
+    
+                // process a sub module
+                if (entryName.endsWith(".jar") || entryName.endsWith(".war"))
+                {
+                   File tmpSubModule = processSubModule(entryName, jis);
+                   FileInputStream fis = new FileInputStream(tmpSubModule);
+                   try{
+                       JarUtils.addJarEntry(jos, entryName, fis);
+                   }finally{
+                       fis.close();
+                   }
+                }
+                else
+                {
+                   if (mapDeploymentPlan.get("!/" + entryName) == null)
+                      JarUtils.addJarEntry(jos, entryName, jis);
+                   else log.debug("Skip entry found in deployment plan: " + entryName);
+                }
+             }
+    
+             entry = jis.getNextJarEntry();
+          }
+    
+          if (moduleType == null)
+          {
+             if (moduleName.endsWith(ModuleType.EAR.getModuleExtension()))
+                moduleType = ModuleType.EAR;
+             else
+                throw new RuntimeException("cannot obtain module type");
+          }
+    
+          moduleInfo.setModuleType(moduleType);
+          // there may be top level deployment plan entries, add them
+          addDeploymentPlanEntry(jos, null);
+    
+          // rename the deployment
+          String deploymentName = tmpFile.getParent() + File.separator + metaData.getDeploymentName();
+          File deployment = new File(deploymentName);
+          if (deployment.exists() && deployment.delete() == false)
+             throw new IOException("Cannot delete existing deployment: " + deployment);
+    
+          tmpFile.renameTo(deployment);
+          moduleInfo.setModuleID(deployment.toURL());
+          return moduleInfo;
+      }finally{
+          if(jis!=null){
+              try{
+                  jis.close();
+              }catch(IOException e){}
+          }
+          
+          if(fos!=null){
+              try{
+                  fos.close();
+              }catch(IOException e){}
+          }
+          
+          if(jos!=null){
+              try{
+                  jos.close();
+              }catch(IOException e){}
+          }
       }
-
-      if (moduleType == null)
-      {
-         if (moduleName.endsWith(ModuleType.EAR.getModuleExtension()))
-            moduleType = ModuleType.EAR;
-         else
-            throw new RuntimeException("cannot obtain module type");
-      }
-
-      moduleInfo.setModuleType(moduleType);
-      // there may be top level deployment plan entries, add them
-      addDeploymentPlanEntry(jos, null);
-      jos.close();
-
-      // rename the deployment
-      String deploymentName = tmpFile.getParent() + File.separator + metaData.getDeploymentName();
-      File deployment = new File(deploymentName);
-      if (deployment.exists() && deployment.delete() == false)
-         throw new IOException("Cannot delete existing deployment: " + deployment);
-
-      tmpFile.renameTo(deployment);
-      moduleInfo.setModuleID(deployment.toURL());
-      return moduleInfo;
    }
 
    public ProgressObject redeploy(TargetModuleID[] targetModuleIDs, File file, File file1) throws UnsupportedOperationException, IllegalStateException
@@ -773,8 +797,11 @@
       File tmpModule = getTempFile(entryName);
       tmpFiles.add(tmpModule);
       FileOutputStream fos = new FileOutputStream(tmpModule);
-      JarUtils.copyStream(fos, jis);
-      fos.close();
+      try{
+          JarUtils.copyStream(fos, jis);
+      }finally{
+          fos.close();
+      }
 
       // now open the copy we just made and copy again entry by entry
       JarInputStream jisModule = new JarInputStream(new FileInputStream(tmpModule));
@@ -787,23 +814,36 @@
          jos = new JarOutputStream(fos, manifest);
       else jos = new JarOutputStream(fos);
 
-      // now copy entry by entry
-      JarEntry entry = jisModule.getNextJarEntry();
-      while (entry != null)
-      {
-         String subEntryName = entry.getName();
-         if (mapDeploymentPlan.get(entryName + "!/" + subEntryName) == null)
-            JarUtils.addJarEntry(jos, subEntryName, jisModule);
-         else log.debug("Skip entry found in deployment plan: " + subEntryName);
-
-         entry = jisModule.getNextJarEntry();
+      try{
+          // now copy entry by entry
+          JarEntry entry = jisModule.getNextJarEntry();
+          while (entry != null)
+          {
+             String subEntryName = entry.getName();
+             if (mapDeploymentPlan.get(entryName + "!/" + subEntryName) == null)
+                JarUtils.addJarEntry(jos, subEntryName, jisModule);
+             else log.debug("Skip entry found in deployment plan: " + subEntryName);
+    
+             entry = jisModule.getNextJarEntry();
+          }
+          
+    
+          addDeploymentPlanEntry(jos, entryName);
+      }finally{
+          if(jisModule!=null){
+              try{
+                  jisModule.close();
+              }catch(IOException e){}
+          }
+          
+          if(jos!=null){
+              try{
+                  jos.close();
+              }catch(IOException e){}
+          }
       }
-      jisModule.close();
+      
 
-      addDeploymentPlanEntry(jos, entryName);
-
-      jos.close();
-
       return tmpJBossModule;
    }
 
@@ -830,8 +870,11 @@
 
             File dpFile = (File)mapDeploymentPlan.get(key);
             FileInputStream dpin = new FileInputStream(dpFile);
-            JarUtils.addJarEntry(jos, dpName, dpin);
-            dpin.close();
+            try{
+                JarUtils.addJarEntry(jos, dpName, dpin);
+            }finally{
+                dpin.close();
+            }
          }
       }
    }
@@ -860,9 +903,11 @@
             dpMap.put(entryName, tempFile);
 
             FileOutputStream out = new FileOutputStream(tempFile);
-            JarUtils.copyStream(out, jarDeploymentPlan);
-            out.close();
-
+            try{
+                JarUtils.copyStream(out, jarDeploymentPlan);
+            }finally{
+                out.close();
+            }
             entry = jarDeploymentPlan.getNextJarEntry();
          }
       }
Index: deployment/src/main/org/jboss/deployment/spi/JarUtils.java
===================================================================
--- deployment/src/main/org/jboss/deployment/spi/JarUtils.java	(revision 113831)
+++ deployment/src/main/org/jboss/deployment/spi/JarUtils.java	(working copy)
@@ -51,20 +51,35 @@
    {
       log.trace("addJar: " + jar);
       ArrayList tmp = new ArrayList();
-      FileInputStream fis = new FileInputStream(jar);
-      JarInputStream jis = new JarInputStream(fis);
-      JarEntry entry = jis.getNextJarEntry();
-      while (entry != null)
-      {
-         if (entry.isDirectory() == false)
-         {
-            String entryName = prefix + entry.getName();
-            tmp.add(entryName);
-            addJarEntry(outputStream, entryName, jis);
-         }
-         entry = jis.getNextJarEntry();
+      FileInputStream fis = null;
+      JarInputStream jis = null;
+      try{
+          fis = new FileInputStream(jar);
+          jis = new JarInputStream(fis);
+          JarEntry entry = jis.getNextJarEntry();
+          while (entry != null)
+          {
+             if (entry.isDirectory() == false)
+             {
+                String entryName = prefix + entry.getName();
+                tmp.add(entryName);
+                addJarEntry(outputStream, entryName, jis);
+             }
+             entry = jis.getNextJarEntry();
+          }
+      }finally{
+          if(fis!=null){
+              try{
+                  fis.close();
+              }catch(Exception e){}
+          }
+          if(jis!=null){
+              try{
+                  jis.close();
+              }catch(Exception e){}
+          }
       }
-      jis.close();
+      
       String[] names = new String[tmp.size()];
       tmp.toArray(names);
       return names;
Index: system-jmx/src/main/org/jboss/deployment/SARDeployer.java
===================================================================
--- system-jmx/src/main/org/jboss/deployment/SARDeployer.java	(revision 113831)
+++ system-jmx/src/main/org/jboss/deployment/SARDeployer.java	(working copy)
@@ -675,8 +675,12 @@
                   }
                   else
                   {
-                     Streams.copyb(jarFile.getInputStream(entry),
-                                   new FileOutputStream(outFile));
+                     FileOutputStream fis = new FileOutputStream(outFile);
+                     try{
+                         Streams.copyb(jarFile.getInputStream(entry),fis);
+                     }finally{
+                         fis.close();
+                     }
                   }
                } // end of if (outFile.exists())
             } // end of if (matches path)
Index: system-jmx/src/main/org/jboss/deployment/SubDeployerSupport.java
===================================================================
--- system-jmx/src/main/org/jboss/deployment/SubDeployerSupport.java	(revision 113831)
+++ system-jmx/src/main/org/jboss/deployment/SubDeployerSupport.java	(working copy)
@@ -535,15 +535,27 @@
             if (!parent.exists()) {
                parent.mkdirs();
             }
+            InputStream in = null;
+            OutputStream out = null;
+            try{
+                in = url.openStream();
+                out = new FileOutputStream(destFile);
+                Streams.copyb(in, out);
+            }finally{
+                if(out!=null){
+                    try{
+                        out.close();
+                    }catch(Exception e){}
+                }
+                if(in!=null){
+                    try{
+                        in.close();
+                    }catch(Exception e){}
+                } 
+            }
+            
+            
 
-            InputStream in = url.openStream();
-            OutputStream out = new FileOutputStream(destFile);
-            Streams.copyb(in, out);
-
-            out.flush();
-            out.close();
-            in.close();
-
             if (loadNative)
                System.load(destFile.toString());
          }
Index: system-jmx/src/main/org/jboss/deployment/XSLSubDeployer.java
===================================================================
--- system-jmx/src/main/org/jboss/deployment/XSLSubDeployer.java	(revision 113831)
+++ system-jmx/src/main/org/jboss/deployment/XSLSubDeployer.java	(working copy)
@@ -229,7 +229,14 @@
          db.setErrorHandler(new JBossErrorHandler(shortURL, resolver));
 
          if (ddSuffix != null && urlStr.endsWith(ddSuffix))
-            di.document = db.parse(di.url.openStream());
+         {
+            InputStream is = di.url.openStream();
+            try{
+                di.document = db.parse(is);
+            }finally{
+                is.close();
+            }
+         }
       }
       catch (SAXException se)
       {
Index: system-jmx/src/main/org/jboss/deployment/MainDeployer.java
===================================================================
--- system-jmx/src/main/org/jboss/deployment/MainDeployer.java	(revision 113831)
+++ system-jmx/src/main/org/jboss/deployment/MainDeployer.java	(working copy)
@@ -1299,18 +1299,35 @@
             log.debug("Making zip copy of: " + srcFile);
             // make a jar archive of the directory
             OutputStream out = new BufferedOutputStream(new FileOutputStream(dest));
-            JarUtils.jar(out, srcFile.listFiles());
-            out.close();
+            try{
+                JarUtils.jar(out, srcFile.listFiles());
+            }finally{
+                out.close();
+            }
             return;
          }
       }
 
-      InputStream in = new BufferedInputStream(src.openStream());
-      OutputStream out = new BufferedOutputStream(new FileOutputStream(dest));
-      Streams.copy(in, out);
-      out.flush();
-      out.close();
-      in.close();
+      InputStream in = null;
+      OutputStream out = null;
+      try{
+          in = new BufferedInputStream(src.openStream());
+          out = new BufferedOutputStream(new FileOutputStream(dest));
+          Streams.copy(in, out);
+      }finally{
+          //BufferedXStream seems to have correct "close" impl
+          if(out!=null){
+              try{
+                  out.close();
+              }catch(Exception e){}
+          }
+          if(in!=null){
+              try{
+                  in.close();
+              }catch(Exception e){}
+          }
+          
+      }
    }
 
    /**
Index: ejb3/src/main/org/jboss/ejb3/deployers/EJBRegistrationDeployer.java
===================================================================
--- ejb3/src/main/org/jboss/ejb3/deployers/EJBRegistrationDeployer.java	(revision 113831)
+++ ejb3/src/main/org/jboss/ejb3/deployers/EJBRegistrationDeployer.java	(working copy)
@@ -94,14 +94,22 @@
          }
          finally
          {
-            try
-            {
-               reader.close();
-               ddStream.close();
-            }
-            catch (IOException ignored)
-            {
-            }
+             try
+             {
+                reader.close();
+             }
+             catch (IOException ignored)
+             {
+             }
+             
+             try
+             {
+                 ddStream.close();
+             }
+             catch (IOException ignored)
+             {
+             }
+            
          }
       }
       catch (Exception ignore)
@@ -202,8 +210,12 @@
          if (ejbjar != null)
          {
             InputStream is = ejbjar.openStream();
-            boolean has30EjbJarXml = has30EjbJarXml(is);
-            is.close();
+            boolean has30EjbJarXml = false;
+            try{
+                has30EjbJarXml = has30EjbJarXml(is);
+            }finally{
+                is.close();
+            }
             if (!has30EjbJarXml) {
                return;
             }
Index: system/src/main/org/jboss/system/server/profileservice/repository/DeploymentUtils.java
===================================================================
--- system/src/main/org/jboss/system/server/profileservice/repository/DeploymentUtils.java	(revision 113831)
+++ system/src/main/org/jboss/system/server/profileservice/repository/DeploymentUtils.java	(working copy)
@@ -97,13 +97,15 @@
             
             // dump the file
             OutputStream out = new FileOutputStream(file);
+            try{
             int len = 0;
             while ((len = jin.read(buffer, 0, buffer.length)) != -1)
             {
                out.write(buffer, 0, len);
             }
-            out.flush();
-            out.close();
+            }finally{
+               out.close();
+            }
             jin.closeEntry();
             file.setLastModified(entry.getTime());
          }
@@ -122,9 +124,11 @@
             parent.mkdirs();
          }
          OutputStream out = new FileOutputStream(file);
-         mf.write(out);
-         out.flush();
-         out.close();
+         try{
+             mf.write(out);
+         }finally{
+             out.close();
+         }
       }
    }
    
Index: system/src/main/org/jboss/system/server/profileservice/repository/clustered/local/file/FileUtil.java
===================================================================
--- system/src/main/org/jboss/system/server/profileservice/repository/clustered/local/file/FileUtil.java	(revision 113831)
+++ system/src/main/org/jboss/system/server/profileservice/repository/clustered/local/file/FileUtil.java	(working copy)
@@ -50,20 +50,34 @@
       if(!source.renameTo(destination))
       {
          // otherwise, copy source to destination
-         OutputStream out = new FileOutputStream(destination);
-         InputStream in = new FileInputStream(source);
-         byte buffer[] = new byte[32*1024];
-         int bytesRead = 0;
-         while(bytesRead > -1) // until we hit end of source file
-         {  
-            bytesRead = in.read(buffer);
-            if(bytesRead > 0) 
-            {
-               out.write(buffer,0, bytesRead);
-            }
+         OutputStream out = null;
+         InputStream in = null;
+         try{
+             out = new FileOutputStream(destination);
+             in = new FileInputStream(source);
+             byte buffer[] = new byte[32*1024];
+             int bytesRead = 0;
+             while(bytesRead > -1) // until we hit end of source file
+             {  
+                bytesRead = in.read(buffer);
+                if(bytesRead > 0) 
+                {
+                   out.write(buffer,0, bytesRead);
+                }
+             }
+         }finally{
+             if(in!=null){
+                 try{
+                     in.close();
+                 }catch(Exception e){}
+             }
+             if(out!=null){
+                 try{
+                     out.close();
+                 }catch(Exception e){}
+             }
          }
-         in.close();
-         out.close();
+         
       }
       
       destination.setLastModified(modifiedTime);
Index: system/src/main/org/jboss/system/server/profileservice/repository/clustered/local/JAXBRepositoryContentMetadataPersister.java
===================================================================
--- system/src/main/org/jboss/system/server/profileservice/repository/clustered/local/JAXBRepositoryContentMetadataPersister.java	(revision 113831)
+++ system/src/main/org/jboss/system/server/profileservice/repository/clustered/local/JAXBRepositoryContentMetadataPersister.java	(working copy)
@@ -23,6 +23,7 @@
 package org.jboss.system.server.profileservice.repository.clustered.local;
 
 import java.io.File;
+import java.io.InputStream;
 import java.net.URI;
 
 import javax.xml.bind.JAXBContext;
@@ -82,7 +83,12 @@
    protected RepositoryContentMetadata loadMetadata(File metadataStore) throws Exception
    {
       Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
-      return (RepositoryContentMetadata) unmarshaller.unmarshal(metadataStore.toURL().openStream(), resolver);
+      InputStream is = metadataStore.toURL().openStream();
+      try{
+          return (RepositoryContentMetadata) unmarshaller.unmarshal(is, resolver);
+      }finally{
+          is.close();
+      }
    }
 
    @Override
Index: tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java
===================================================================
--- tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java	(revision 113831)
+++ tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java	(working copy)
@@ -135,7 +135,11 @@
          InputStream is = TomcatInjectionContainer.class.getClassLoader().getResourceAsStream("org/apache/catalina/core/RestrictedServlets.properties");
          if (is != null)
          {
-            restrictedServlets.load(is);
+             try{
+                 restrictedServlets.load(is);
+             }finally{
+                 is.close();
+             }
          }
          else
          {
@@ -152,7 +156,12 @@
          InputStream is = TomcatInjectionContainer.class.getClassLoader().getResourceAsStream("org/apache/catalina/core/RestrictedListeners.properties");
          if (is != null)
          {
-            restrictedListeners.load(is);
+             try{
+                 restrictedListeners.load(is);
+             }finally{
+                 is.close();
+             }
+            
          }
          else
          {
@@ -168,7 +177,11 @@
          InputStream is = TomcatInjectionContainer.class.getClassLoader().getResourceAsStream("org/apache/catalina/core/RestrictedFilters.properties");
          if (is != null)
          {
-            restrictedFilters.load(is);
+             try{
+                 restrictedFilters.load(is);
+             }finally{
+                 is.close();
+             }
          }
          else
          {
Index: spring-int/src/test/org/jboss/tutorial/spring/FileLineReader.java
===================================================================
--- spring-int/src/test/org/jboss/tutorial/spring/FileLineReader.java	(revision 113831)
+++ spring-int/src/test/org/jboss/tutorial/spring/FileLineReader.java	(working copy)
@@ -22,6 +22,7 @@
 package org.jboss.tutorial.spring;
 
 import java.io.BufferedReader;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
@@ -54,9 +55,12 @@
       {
          throw new IllegalArgumentException("Resource must be set!");
       }
-      BufferedReader reader = new BufferedReader(new InputStreamReader(getResource().getInputStream()));
+      InputStream is = null;
+      BufferedReader reader = null;
       try
       {
+         is = getResource().getInputStream();
+         reader = new BufferedReader(new InputStreamReader(is));
          words = new ArrayList<String>();
          String line;
          while ((line = reader.readLine()) != null)
@@ -66,7 +70,17 @@
       }
       finally
       {
-         reader.close();
+          if(is!=null){
+              try{
+                  is.close();
+              }catch(Exception e){}
+          }
+          
+          if(reader!=null){
+              try{
+                  reader.close();
+              }catch(Exception e){}
+          }
       }
    }
 
Index: varia/src/main/org/jboss/tools/license/ValidateLicenseHeaders.java
===================================================================
--- varia/src/main/org/jboss/tools/license/ValidateLicenseHeaders.java	(revision 113831)
+++ varia/src/main/org/jboss/tools/license/ValidateLicenseHeaders.java	(working copy)
@@ -406,16 +406,35 @@
    {
       if( log.isLoggable(Level.FINE) )
          log.fine("Replacing legacy jboss header in: "+javaFile);
-      RandomAccessFile raf = new RandomAccessFile(javaFile, "rw");
       File bakFile = new File(javaFile.getAbsolutePath()+".bak");
-      FileOutputStream fos = new FileOutputStream(bakFile);
-      fos.write(DEFAULT_HEADER.getBytes());
-      FileChannel fc = raf.getChannel();
-      long count = raf.length() - endOfHeader;
-      fc.transferTo(endOfHeader, count, fos.getChannel());
-      fc.close();
-      fos.close();
-      raf.close();
+      RandomAccessFile raf = null;
+      FileOutputStream fos = null;
+      FileChannel fc = null;
+      try{
+          
+          raf = new RandomAccessFile(javaFile, "rw");
+          fos = new FileOutputStream(bakFile);
+          fos.write(DEFAULT_HEADER.getBytes());
+          fc = raf.getChannel();
+          long count = raf.length() - endOfHeader;
+          fc.transferTo(endOfHeader, count, fos.getChannel());
+       }finally{
+           if(fc!=null){
+               try{
+                   fc.close();
+               } catch(Exception e){}
+           }
+           if(fos!=null){
+               try{
+                   fos.close();
+               } catch(Exception e){}
+           }
+           if(raf!=null){
+               try{
+                   raf.close();
+               } catch(Exception e){}
+           }
+       }
       if( javaFile.delete() == false )
          log.severe("Failed to delete java file: "+javaFile);
       if( bakFile.renameTo(javaFile) == false )
Index: varia/src/main/org/jboss/tools/SerialVersionUID.java
===================================================================
--- varia/src/main/org/jboss/tools/SerialVersionUID.java	(revision 113831)
+++ varia/src/main/org/jboss/tools/SerialVersionUID.java	(working copy)
@@ -223,9 +223,24 @@
          classVersionMap = generateJBossSerialVersionUIDReport(distHome);
       // Write the map out the object file
       log.info("Total classes with serialVersionUID != 0: "+classVersionMap.size());
-      FileOutputStream fos = new FileOutputStream("serialuid.ser");
-      ObjectOutputStream oos = new ObjectOutputStream(fos);
-      oos.writeObject(classVersionMap);
-      fos.close();
+      FileOutputStream fos = null;
+      ObjectOutputStream oos = null;
+      try{
+          fos = new FileOutputStream("serialuid.ser");
+          oos = new ObjectOutputStream(fos);
+          oos.writeObject(classVersionMap);
+      }finally{
+          if(fos!=null){
+              try{
+                  fos.close();
+              }catch(Exception e){}
+          }
+          
+          if(oos!=null){
+              try{
+                  oos.close();
+              }catch(Exception e){}
+          }
+      }
    }
 }
Index: varia/src/main/org/jboss/varia/deployment/FoeDeployer.java
===================================================================
--- varia/src/main/org/jboss/varia/deployment/FoeDeployer.java	(revision 113831)
+++ varia/src/main/org/jboss/varia/deployment/FoeDeployer.java	(working copy)
@@ -455,8 +455,12 @@
    {
       File destFile = new File(fileURL.getFile());
       InputStream input = new FileInputStream(fileURL.getFile());
-      JarUtils.unjar(input, destinationDirectory);
-      // input is closed in unjar();
+      try{
+          JarUtils.unjar(input, destinationDirectory);
+      }finally {
+          input.close();
+      }
+
    }
 
    /**
@@ -470,8 +474,11 @@
       throws Exception
    {
       OutputStream output = new FileOutputStream(jarFile);
-      JarUtils.jar(output, root.listFiles(), null, null, null);
-      output.close();
+      try{
+         JarUtils.jar(output, root.listFiles(), null, null, null);
+       }finally {
+           output.close();
+       }
    }
 
    /**
Index: varia/src/main/org/jboss/varia/property/SystemPropertiesService.java
===================================================================
--- varia/src/main/org/jboss/varia/property/SystemPropertiesService.java	(revision 113831)
+++ varia/src/main/org/jboss/varia/property/SystemPropertiesService.java	(working copy)
@@ -246,8 +246,13 @@
 
       Properties props = System.getProperties();
       InputStream is = url.openConnection().getInputStream();
-      props.load(is);
-      is.close();
+      try{
+          props.load(is);
+      }finally{
+          try{
+              is.close();
+          }catch(Exception e){}
+      }
 
       log.info("Loaded system properties from: " + url);
    }
Index: varia/src/main/org/jboss/services/deployment/DeploymentManager.java
===================================================================
--- varia/src/main/org/jboss/services/deployment/DeploymentManager.java	(revision 113831)
+++ varia/src/main/org/jboss/services/deployment/DeploymentManager.java	(working copy)
@@ -636,19 +636,22 @@
    {
       // get the XML stream
       InputStream is = new FileInputStream(file);
-
-      // create unmarshaller
-      Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
-
-      // create an instance of ObjectModelFactory
-      ObjectModelFactory factory = new ConfigInfoBinding();
-
-      // let the object model factory to create an instance of Book and populate it with data from XML
-      ConfigInfo ci = (ConfigInfo)unmarshaller.unmarshal(is, factory, null);
-
-      // close the XML stream
-      is.close();
-
+      ConfigInfo ci = null;
+      try{
+          // create unmarshaller
+          Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+    
+          // create an instance of ObjectModelFactory
+          ObjectModelFactory factory = new ConfigInfoBinding();
+    
+          // let the object model factory to create an instance of Book and populate it with data from XML
+          ci = (ConfigInfo)unmarshaller.unmarshal(is, factory, null);
+    
+          // close the XML stream
+          is.close();
+      }finally{
+          is.close();
+      }
       return ci;
    }
 
@@ -816,14 +819,31 @@
       // place the generated file into the undeploy directory:
       File configFile = new File(path);
       File outputFile = new File(this.undeployDir, configFile.getName());
-      InputStream configStream = new FileInputStream(configFile);
-      InputStream xsltStream = new StringBufferInputStream(buf.toString());
-      OutputStream outputStream = new FileOutputStream(outputFile);
-      XslTransformer.applyTransformation(configStream, outputStream, xsltStream, null);
-      configStream.close();
-      xsltStream.close();
-      outputStream.close();
-
+      InputStream configStream = null;
+      InputStream xsltStream = null;
+      OutputStream outputStream = null;
+      try{
+          configStream = new FileInputStream(configFile);
+          xsltStream = new StringBufferInputStream(buf.toString());
+          outputStream = new FileOutputStream(outputFile);
+          XslTransformer.applyTransformation(configStream, outputStream, xsltStream, null);
+      }finally{
+          if(configStream!=null){
+              try{
+                  configStream.close();
+              }catch(Exception e){}
+          }
+          if(xsltStream!=null){
+              try{
+                  xsltStream.close();
+              }catch(Exception e){}
+          }
+          if(outputStream!=null){
+              try{
+                  outputStream.close();
+              }catch(Exception e){}
+          }
+      }
       // Now that we have the generated file, move it to its proper location
       if (!configFile.delete())
          throw new Exception("Update failed for '" + name + "', unable to delete old configuration file: " + path);
Index: varia/src/main/org/jboss/services/binding/impl/XSLTServiceBindingValueSourceImpl.java
===================================================================
--- varia/src/main/org/jboss/services/binding/impl/XSLTServiceBindingValueSourceImpl.java	(revision 113831)
+++ varia/src/main/org/jboss/services/binding/impl/XSLTServiceBindingValueSourceImpl.java	(working copy)
@@ -166,6 +166,7 @@
          XSLTServiceBindingValueSourceConfig config)
    {
       Writer writer = null;
+      FileOutputStream fos = null;
       File targetFile = null;
       try
       {
@@ -176,7 +177,8 @@
                return Util.createTempFile();
             }
          });
-         writer = new OutputStreamWriter(new FileOutputStream(targetFile));
+         fos = new FileOutputStream(targetFile);
+         writer = new OutputStreamWriter(fos);
          
          doXslTransform(binding, config, reader, writer);
 
@@ -199,6 +201,17 @@
                log.warn("Failed closing Reader for " + input, e);
             }
          }
+         if (fos != null)
+         {
+            try
+            {
+                fos.close();
+            }
+            catch (IOException e)
+            {
+               log.warn("Failed closing Reader for " + input, e);
+            }
+         }
          if (writer != null)
          {
             try
Index: varia/src/main/org/jboss/services/binding/impl/Util.java
===================================================================
--- varia/src/main/org/jboss/services/binding/impl/Util.java	(revision 113831)
+++ varia/src/main/org/jboss/services/binding/impl/Util.java	(working copy)
@@ -92,13 +92,21 @@
    public static String getContentAsString(URL url) throws IOException
    {
       InputStreamReader isr = getInputStreamReader(url);
-      return getContentAsString(isr);
+      try{
+          return getContentAsString(isr);
+      }finally{
+          isr.close();
+      }
    }
    
    public static String getContentAsString(String resource) throws IOException
    {
       InputStreamReader isr = getInputStreamReader(resource);
-      return getContentAsString(isr);
+      try{
+          return getContentAsString(isr);
+      }finally{
+          isr.close();
+      }
    }
    
    public static File writeToTempFile(String content) throws IOException
Index: varia/src/main/org/jboss/security/srp/SerialObjectStore.java
===================================================================
--- varia/src/main/org/jboss/security/srp/SerialObjectStore.java	(revision 113831)
+++ varia/src/main/org/jboss/security/srp/SerialObjectStore.java	(working copy)
@@ -77,17 +77,32 @@
             storeFile = new File("SerialObjectStore.ser");
         if( storeFile.exists() == true )
         {
-            FileInputStream fis = new FileInputStream(storeFile);
-            ObjectInputStream ois = new ObjectInputStream(fis);
-            try
-            {
-                infoMap = (Map) ois.readObject();
+            FileInputStream fis = null;
+            ObjectInputStream ois = null;
+            try{
+                fis = new FileInputStream(storeFile);
+                ois = new ObjectInputStream(fis);
+                try
+                {
+                    infoMap = (Map) ois.readObject();
+                }
+                catch(ClassNotFoundException e)
+                {
+                }
+            }finally{
+                if(ois!=null){
+                    try{
+                        ois.close();
+                    }catch(Exception e){}
+                }
+                
+                if(fis!=null){
+                    try{
+                        fis.close();
+                    }catch(Exception e){}
+                }
             }
-            catch(ClassNotFoundException e)
-            {
-            }
-            ois.close();
-            fis.close();
+            
         }
         else
         {
@@ -140,14 +155,28 @@
     */
     public void save(File storeFile) throws IOException
     {
-        FileOutputStream fos = new FileOutputStream(storeFile);
-        ObjectOutputStream oos = new ObjectOutputStream(fos);
-        synchronized( infoMap )
-        {
-            oos.writeObject(infoMap);
+        FileOutputStream fos = null;
+        ObjectOutputStream oos = null;
+        try{
+            fos = new FileOutputStream(storeFile);
+            oos = new ObjectOutputStream(fos);
+            synchronized( infoMap )
+            {
+                oos.writeObject(infoMap);
+            }
+        }finally{
+            if(oos!=null){
+                try{
+                    oos.close();
+                }catch(Exception e){}
+            }
+            
+            if(fos!=null){
+                try{
+                    fos.close();
+                }catch(Exception e){}
+            }
         }
-        oos.close();
-        fos.close();
     }
 
     public void addUser(String username, String password)
Index: varia/src/main/org/jboss/invocation/http/servlet/InvokerServlet.java
===================================================================
--- varia/src/main/org/jboss/invocation/http/servlet/InvokerServlet.java	(revision 113831)
+++ varia/src/main/org/jboss/invocation/http/servlet/InvokerServlet.java	(working copy)
@@ -132,10 +132,24 @@
          if( mi == null )
          {
             // Get the invocation from the post
-            ServletInputStream sis = request.getInputStream();
-            ObjectInputStream ois = new ObjectInputStream(sis);
-            mi = (MarshalledInvocation) ois.readObject();
-            ois.close();
+             ServletInputStream sis = null;
+             ObjectInputStream ois = null;
+             try{
+                 sis = request.getInputStream();
+                 ois = new ObjectInputStream(sis);
+                 mi = (MarshalledInvocation) ois.readObject();
+            }finally{
+                if(ois!=null){
+                    try{
+                        ois.close();
+                    }catch(Exception e){}
+                }
+                if(sis!=null){
+                    try{
+                        sis.close();
+                    }catch(Exception e){}
+                }
+            }
          }
          /* If the invocation carries no auth context, look to to the auth
          context of this servlet as seen in the SecurityAssocation. This allows
@@ -163,10 +177,24 @@
          if( returnValueAsAttribute == null || returnValueAsAttribute.booleanValue() == false )
          {
             MarshalledValue mv = new MarshalledValue(value);
-            ServletOutputStream sos = response.getOutputStream();
-            ObjectOutputStream oos = new ObjectOutputStream(sos);
-            oos.writeObject(mv);
-            oos.close();
+            ServletOutputStream sos = null;
+            ObjectOutputStream oos = null;
+            try{
+                sos = response.getOutputStream();
+                oos = new ObjectOutputStream(sos);
+                oos.writeObject(mv);
+            }finally{
+                if(oos!=null){
+                    try{
+                        oos.close();
+                    }catch(Exception e){}
+                }
+                if(sos!=null){
+                    try{
+                        sos.close();
+                    }catch(Exception e){}
+                }
+            }
          }
          else
          {
@@ -192,10 +220,25 @@
          {
             response.resetBuffer();
             MarshalledValue mv = new MarshalledValue(appException);
-            ServletOutputStream sos = response.getOutputStream();
-            ObjectOutputStream oos = new ObjectOutputStream(sos);
-            oos.writeObject(mv);
-            oos.close();
+            ServletOutputStream sos = null;
+            ObjectOutputStream oos = null;
+            try{
+                sos = response.getOutputStream();
+                oos = new ObjectOutputStream(sos);
+                oos.writeObject(mv);
+            }finally{
+                if(oos!=null){
+                    try{
+                        oos.close();
+                    }catch(Exception e){}
+                }
+                if(sos!=null){
+                    try{
+                        sos.close();
+                    }catch(Exception e){}
+                }
+            }
+            
          }
          else
          {
Index: varia/src/main/org/jboss/invocation/http/servlet/ReadOnlyAccessFilter.java
===================================================================
--- varia/src/main/org/jboss/invocation/http/servlet/ReadOnlyAccessFilter.java	(revision 113831)
+++ varia/src/main/org/jboss/invocation/http/servlet/ReadOnlyAccessFilter.java	(working copy)
@@ -98,17 +98,33 @@
       if( user == null && readOnlyContext != null )
       {
          // Extract the invocation
-         ServletInputStream sis = request.getInputStream();
-         ObjectInputStream ois = new ObjectInputStream(sis);
-         MarshalledInvocation mi = null;
-         try
-         {
-            mi = (MarshalledInvocation) ois.readObject();
-         }
-         catch(ClassNotFoundException e)
-         {
-            throw new ServletException("Failed to read MarshalledInvocation", e);
-         }
+          ServletInputStream sis = null;
+          ObjectInputStream ois = null;
+          MarshalledInvocation mi = null;
+          try{
+             sis = request.getInputStream();
+             ois = new ObjectInputStream(sis);
+            
+             try
+             {
+                mi = (MarshalledInvocation) ois.readObject();
+             }
+             catch(ClassNotFoundException e)
+             {
+                throw new ServletException("Failed to read MarshalledInvocation", e);
+             }
+          }finally{
+              if(ois!=null){
+                  try{
+                      ois.close();
+                  }catch(Exception e){}
+              }
+              if(sis!=null){
+                  try{
+                      sis.close();
+                  }catch(Exception e){}
+              }
+          }
          request.setAttribute("MarshalledInvocation", mi);
          /* Get the invocation method. If there is no method then this must
             be an invocation on an mbean other than our invoker so let it go
Index: varia/src/main/org/jboss/invocation/http/servlet/NamingFactoryServlet.java
===================================================================
--- varia/src/main/org/jboss/invocation/http/servlet/NamingFactoryServlet.java	(revision 113831)
+++ varia/src/main/org/jboss/invocation/http/servlet/NamingFactoryServlet.java	(working copy)
@@ -117,11 +117,25 @@
          if( trace )
             log.trace("Serialized Naming proxy, size="+mv.size());
          //response.setContentLength(mv.size());
-         ServletOutputStream sos = response.getOutputStream();
-         ObjectOutputStream oos = new ObjectOutputStream(sos);
-         oos.writeObject(mv);
-         oos.flush();
-         oos.close();
+         ServletOutputStream sos = null;
+         ObjectOutputStream oos = null;
+         try{
+             sos = response.getOutputStream();
+             oos = new ObjectOutputStream(sos);
+             oos.writeObject(mv);
+             oos.flush();
+         }finally{
+             if(oos!=null){
+                 try{
+                     oos.close();
+                 }catch(Exception e){}
+             }
+             if(sos!=null){
+                 try{
+                     sos.close();
+                 }catch(Exception e){}
+             }
+         }
       }
       catch(Throwable t)
       {
@@ -129,10 +143,25 @@
          // Marshall the exception
          response.resetBuffer();
          MarshalledValue mv = new MarshalledValue(t);
-         ServletOutputStream sos = response.getOutputStream();
-         ObjectOutputStream oos = new ObjectOutputStream(sos);
-         oos.writeObject(mv);
-         oos.close();
+         ServletOutputStream sos = null;
+         ObjectOutputStream oos = null;
+         try{
+             sos = response.getOutputStream();
+             oos = new ObjectOutputStream(sos);
+             oos.writeObject(mv);
+             oos.flush();
+         }finally{
+             if(oos!=null){
+                 try{
+                     oos.close();
+                 }catch(Exception e){}
+             }
+             if(sos!=null){
+                 try{
+                     sos.close();
+                 }catch(Exception e){}
+             }
+         }
       }
 
    }
Index: j2se/src/main/org/jboss/mx/loading/MLetParser.java
===================================================================
--- j2se/src/main/org/jboss/mx/loading/MLetParser.java	(revision 113831)
+++ j2se/src/main/org/jboss/mx/loading/MLetParser.java	(working copy)
@@ -33,6 +33,7 @@
 
 import java.io.IOException;
 import java.io.BufferedReader;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 
 import org.jboss.logging.Logger;
@@ -81,9 +82,13 @@
       Set mlets            = new HashSet(); 
       MBeanElement element = null;
 
+      InputStream is = null;
+      BufferedReader reader = null;
       try
       {         
-         BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
+         is = url.openStream();
+         reader = new BufferedReader(new InputStreamReader(is));
+        
          int c                 = -1;
       
          // read the file
@@ -224,6 +229,15 @@
       catch (IOException e) 
       {
          throw new ParseException(e.toString(), 0);
+      } finally{
+          if(is!=null)
+              try{
+                  is.close();
+              }catch(Exception e){}
+          if(reader!=null)
+              try{
+                  reader.close();
+              }catch(Exception e){}
       }
    }
    
Index: server/src/main/org/jboss/naming/ExternalContext.java
===================================================================
--- server/src/main/org/jboss/naming/ExternalContext.java	(revision 113831)
+++ server/src/main/org/jboss/naming/ExternalContext.java	(working copy)
@@ -415,7 +415,11 @@
          {
             URL url = new URL(contextPropsURL);
             is = url.openStream();
-            contextProps.load(is);
+            try{
+                contextProps.load(is);
+            } finally{
+                is.close();
+            }
             return;
          }
          catch (IOException e)
@@ -428,7 +432,11 @@
          {
             throw new IOException("Failed to locate context props as URL or resource:"+contextPropsURL);
          }
-         contextProps.load(is);
+         try{
+             contextProps.load(is);
+         } finally{
+             is.close();
+         }
       }
 
       Context newContext() throws Exception
Index: server/src/main/org/jboss/verifier/factory/DefaultEventFactory.java
===================================================================
--- server/src/main/org/jboss/verifier/factory/DefaultEventFactory.java	(revision 113831)
+++ server/src/main/org/jboss/verifier/factory/DefaultEventFactory.java	(working copy)
@@ -143,7 +143,13 @@
       {
          InputStream in = getClass().getResourceAsStream( msgBundle );
          Properties  props = new Properties();
-         props.load(in);
+         try{
+             props.load(in);
+         } finally {
+             try{
+                 in.close();
+             } catch(Exception e){}
+         }
 
         return props;
       }
Index: server/src/main/org/jboss/web/WebServer.java
===================================================================
--- server/src/main/org/jboss/web/WebServer.java	(revision 113831)
+++ server/src/main/org/jboss/web/WebServer.java	(working copy)
@@ -515,16 +515,33 @@
     */
    protected byte[] getBytes(URL url) throws IOException
    {
-      InputStream in = new BufferedInputStream(url.openStream());
-      log.debug("Retrieving " + url);
-      ByteArrayOutputStream out = new ByteArrayOutputStream();
-      byte[] tmp = new byte[1024];
-      int bytes;
-      while ((bytes = in.read(tmp)) != -1)
-      {
-         out.write(tmp, 0, bytes);
-      }
-      in.close();
+       InputStream is = null; 
+       InputStream in = null;
+       ByteArrayOutputStream out = new ByteArrayOutputStream();
+       try{
+          is = url.openStream(); 
+          in = new BufferedInputStream(is);
+          log.debug("Retrieving " + url);
+          
+          byte[] tmp = new byte[1024];
+          int bytes;
+          while ((bytes = in.read(tmp)) != -1)
+          {
+             out.write(tmp, 0, bytes);
+          }
+       }finally{
+           if(is!=null){
+               try{
+                   is.close();
+               }catch(Exception e){}
+           }
+           if(in!=null){
+               try{
+                   in.close();
+               }catch(Exception e){}
+           }
+       }
+      
       return out.toByteArray();
    }
 
Index: server/src/main/org/jboss/web/WebService.java
===================================================================
--- server/src/main/org/jboss/web/WebService.java	(revision 113831)
+++ server/src/main/org/jboss/web/WebService.java	(working copy)
@@ -21,6 +21,7 @@
  */
 package org.jboss.web;
 
+import java.io.InputStream;
 import java.net.InetAddress;
 import java.net.URL;
 import java.net.UnknownHostException;
@@ -273,10 +274,11 @@
    {
       // Load the file mime.types into the mapping list
       Properties mimeTypes = new Properties();
-
+      InputStream is = null;
       try
       {
-         mimeTypes.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jboss/web/mime.types"));
+         is =Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jboss/web/mime.types");
+         mimeTypes.load(is);
 
          Enumeration keys = mimeTypes.keys();
          while (keys.hasMoreElements())
@@ -289,6 +291,12 @@
       catch (Exception e)
       {
          log.error("Failed to load org/jboss/web/mime.types; ignoring", e);
+      } finally{
+          if(is!=null){
+              try{
+                  
+              } catch(Exception e){}
+          }
       }
 
       // if no override has been specified, default to the jboss bind address
Index: server/src/main/org/jboss/client/AppClientMain.java
===================================================================
--- server/src/main/org/jboss/client/AppClientMain.java	(revision 113831)
+++ server/src/main/org/jboss/client/AppClientMain.java	(working copy)
@@ -157,8 +157,13 @@
       if( appXmlURL != null )
       {
          InputStream is = appXmlURL.openStream();
-         Document appXml = builder.parse(is);
-         is.close();
+         Document appXml;
+         try{
+             appXml = builder.parse(is);
+         }finally{
+          is.close();   
+         }
+         
          Element root = appXml.getDocumentElement();
          clientName = root.getAttribute("id");
          if( clientName != null )
@@ -170,8 +175,14 @@
       if( appXmlURL != null )
       {
          InputStream is = jbossXmlURL.openStream();
-         Document jbossXml = builder.parse(is);
-         is.close();
+         Document jbossXml;
+         try{
+             jbossXml = builder.parse(is);
+         }finally{
+             is.close(); 
+         }
+         
+         
          Element root = jbossXml.getDocumentElement();
          NodeList children = root.getChildNodes();
          for(int n = 0; n < children.getLength(); n ++)
Index: webservices/src/main/org/jboss/wsf/container/jboss50/deployer/ArchiveDeployerHook.java
===================================================================
--- webservices/src/main/org/jboss/wsf/container/jboss50/deployer/ArchiveDeployerHook.java	(revision 113831)
+++ webservices/src/main/org/jboss/wsf/container/jboss50/deployer/ArchiveDeployerHook.java	(working copy)
@@ -21,6 +21,7 @@
  */
 package org.jboss.wsf.container.jboss50.deployer;
 
+import java.io.InputStream;
 import java.net.URL;
 
 import org.jboss.deployers.spi.DeploymentException;
@@ -118,13 +119,28 @@
          try
          {
             URL wsURL = vfWebservices.toURL();
-            Element root = DOMUtils.parse(wsURL.openStream());
+            InputStream is =wsURL.openStream();
+            Element root = null;
+            try{
+                root = DOMUtils.parse(is);
+            }finally{
+                try{
+                    is.close();
+                }catch(Exception e){}
+            }
             String namespaceURI = root.getNamespaceURI();
             if (namespaceURI.equals("http://java.sun.com/xml/ns/j2ee"))
             {
                Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
                ObjectModelFactory factory = new WebservicesFactory(wsURL);
-               wsMetaData = (WebservicesMetaData)unmarshaller.unmarshal(wsURL.openStream(), factory, null);
+               is = wsURL.openStream();
+               try{
+                   wsMetaData = (WebservicesMetaData)unmarshaller.unmarshal(wsURL.openStream(), factory, null);
+               }finally{
+                   try{
+                       is.close();
+                   }catch(Exception e){}
+               }
                unit.addAttachment(WebservicesMetaData.class, wsMetaData);
             }
          }
Index: main/src/main/org/jboss/check/JARCheck.java
===================================================================
--- main/src/main/org/jboss/check/JARCheck.java	(revision 113831)
+++ main/src/main/org/jboss/check/JARCheck.java	(working copy)
@@ -73,10 +73,11 @@
     }
 
     public static void check(File f) throws NoSuchAlgorithmException {
+        FileInputStream fis = null;
         try {
             MessageDigest alg = MessageDigest.getInstance("md5");
             JarFile jf = new JarFile(f);
-            FileInputStream fis = new FileInputStream(f);
+            fis = new FileInputStream(f);
             byte [] buffer = new byte[(int) f.length()];
             fis.read(buffer);
             alg.update(buffer);
@@ -94,6 +95,12 @@
         }
         catch( java.io.IOException ioe ) {
             System.err.println(ioe.toString());
+        } finally {
+            if(fis!=null){
+                try{
+                    fis.close();
+                }catch(Exception e){}
+            }
         }
     }
 }
Index: embedded/src/main/java/org/jboss/embedded/BeanCompiler.java
===================================================================
--- embedded/src/main/java/org/jboss/embedded/BeanCompiler.java	(revision 113831)
+++ embedded/src/main/java/org/jboss/embedded/BeanCompiler.java	(working copy)
@@ -59,18 +59,44 @@
 
       long start = System.currentTimeMillis();
 
-      FileOutputStream fos = new FileOutputStream(arg + ".bin");
-      ObjectOutputStream oos = new ObjectOutputStream(fos);
-      oos.writeObject(deployment);
-      oos.close();
-      fos.close();
+      FileOutputStream fos = null;
+      ObjectOutputStream oos = null;
+      try{
+          fos = new FileOutputStream(arg + ".bin");
+          oos = new ObjectOutputStream(fos);
+          oos.writeObject(deployment);
+      }finally{
+          if(fos!=null){
+              try{
+                  fos.close();
+              }catch(Exception e){}
+          }
+          if(oos!=null){
+              try{
+                  oos.close();
+              }catch(Exception e){}
+          }
+      }
+      FileInputStream fis = null;
+      ObjectInputStream ois = null;
+      try{
+          fis = new FileInputStream(arg + ".bin");
+          ois = new ObjectInputStream(fis);
+          deployment = (KernelDeployment)ois.readObject();
+      }finally{
+          if(fis!=null){
+              try{
+                  fis.close();
+              }catch(Exception e){}
+          }
+          if(ois!=null){
+              try{
+                  ois.close();
+              }catch(Exception e){}
+          }
+      }
+      
 
-      FileInputStream fis = new FileInputStream(arg + ".bin");
-      ObjectInputStream ois = new ObjectInputStream(fis);
-      deployment = (KernelDeployment)ois.readObject();
-      ois.close();
-      fis.close();
-
       long end = System.currentTimeMillis() - start;
 
       System.out.println("object loading took: " + end);
Index: embedded/src/main/java/org/jboss/embedded/BinaryBootstrap.java
===================================================================
--- embedded/src/main/java/org/jboss/embedded/BinaryBootstrap.java	(revision 113831)
+++ embedded/src/main/java/org/jboss/embedded/BinaryBootstrap.java	(working copy)
@@ -84,12 +84,18 @@
       try
       {
          oos.writeObject(deployment);
+      }finally{
+          if(fos!=null){
+              try{
+                  fos.close();
+              }catch(Exception e){}
+          }
+          if(oos!=null){
+              try{
+                  oos.close();
+              }catch(Exception e){}
+          }
       }
-      finally
-      {
-         oos.close();
-         fos.close();
-      }
    }
 
    public static KernelDeployment load(File binFile) throws Exception
@@ -99,12 +105,18 @@
       try
       {
          return (KernelDeployment)ois.readObject();
+      }finally{
+          if(fis!=null){
+              try{
+                  fis.close();
+              }catch(Exception e){}
+          }
+          if(ois!=null){
+              try{
+                  ois.close();
+              }catch(Exception e){}
+          }
       }
-      finally
-      {
-         ois.close();
-         fis.close();
-      }
    }
 
    @Override
Index: jmx/src/main/org/jboss/mx/loading/ClassLoaderUtils.java
===================================================================
--- jmx/src/main/org/jboss/mx/loading/ClassLoaderUtils.java	(revision 113831)
+++ jmx/src/main/org/jboss/mx/loading/ClassLoaderUtils.java	(working copy)
@@ -334,6 +334,9 @@
       boolean trace = log.isTraceEnabled();
       InputStream zis = cpi.getInputStream();
       BufferedReader br = new BufferedReader(new InputStreamReader(zis));
+      try{
+      zis = cpi.getInputStream();
+      br = new BufferedReader(new InputStreamReader(zis));
       String line;
       // Skip the jar index header
       while( (line = br.readLine()) != null )
@@ -353,7 +356,21 @@
          String pkgName = line.replace('/', '.');
          listener.addPackage(pkgName);
       }
-      br.close();
+      }finally{
+          if(br!=null){
+              try{
+                  br.close();
+              }catch(Exception e){}
+          }
+          
+          if(zis!=null){
+              try{
+                  zis.close();
+              }catch(Exception e){}
+          }
+             
+      }
+      
    }
 
    /** Add a class name to the UCL map.
@@ -503,6 +520,7 @@
    static class ClassPathIterator
    {
       ZipInputStream zis;
+      InputStream is;
       FileIterator fileIter;
       File file;
       int rootLength;
@@ -524,14 +542,14 @@
             else
             {
                // Assume this is a jar archive
-               InputStream is = new FileInputStream(tmp);
+               is = new FileInputStream(tmp);
                zis = new ZipInputStream(is);
             }
          }
          else
          {
             // Assume this points to a jar
-            InputStream is = url.openStream();
+            is = url.openStream();
             zis = new ZipInputStream(is);
          }
       }
@@ -568,8 +586,15 @@
 
       void close() throws IOException
       {
-         if( zis != null )
-            zis.close();
+         if(is!=null){
+             try{
+                 is.close();
+             }finally{
+                 if( zis != null )
+                     zis.close();
+             }
+         }
+         
       }
 
    }
Index: jmx/src/main/org/jboss/mx/loading/ClassPreloadService.java
===================================================================
--- jmx/src/main/org/jboss/mx/loading/ClassPreloadService.java	(revision 113831)
+++ jmx/src/main/org/jboss/mx/loading/ClassPreloadService.java	(working copy)
@@ -141,10 +141,12 @@
       for(int n = 0; n < cp.length; n ++)
       {
          URL u = cp[n];
+         InputStream is = null;
+         ZipInputStream zis = null;
          try
          {
-            InputStream is = u.openStream();
-            ZipInputStream zis = new ZipInputStream(is);
+            is = u.openStream();
+            zis = new ZipInputStream(is);
             ZipEntry ze = zis.getNextEntry();
             while (ze != null)
             {
@@ -169,11 +171,22 @@
                }
                ze = zis.getNextEntry();
             }
-            zis.close();
+            
          }
          catch (IOException ignore)
          {
             // Not a jar
+         } finally{
+             if(is!=null){
+                 try{
+                     is.close();
+                 }catch(Exception e){}
+             }
+             if(zis!=null){
+                 try{
+                     zis.close();
+                 }catch(Exception e){}
+             }
          }
       }
       log.info("Loaded "+loadedClasses+" classes, "+loadErrors+" CNFEs");
Index: iiop/src/main/org/jboss/iiop/CorbaORBService.java
===================================================================
--- iiop/src/main/org/jboss/iiop/CorbaORBService.java	(revision 113831)
+++ iiop/src/main/org/jboss/iiop/CorbaORBService.java	(working copy)
@@ -208,7 +208,13 @@
       // Read orb properties file into props
       ClassLoader cl = Thread.currentThread().getContextClassLoader();
       InputStream is = cl.getResourceAsStream(orbPropertiesFileName);
-      props.load(is);
+      try{
+          props.load(is);
+      } finally {
+          try{
+              is.close();
+          } catch(Exception e){}
+      }
       
       String oaiAddr = props.getProperty("OAIAddr");
       if (oaiAddr == null)
Index: console/src/main/org/jboss/console/plugins/helpers/BasePluginWrapper.java
===================================================================
--- console/src/main/org/jboss/console/plugins/helpers/BasePluginWrapper.java	(revision 113831)
+++ console/src/main/org/jboss/console/plugins/helpers/BasePluginWrapper.java	(working copy)
@@ -32,6 +32,8 @@
 import javax.management.MBeanServer;
 import javax.management.ObjectInstance;
 import javax.servlet.ServletConfig;
+
+import java.io.InputStream;
 import java.lang.reflect.UndeclaredThrowableException;
 import java.net.URL;
 
@@ -192,7 +194,14 @@
       //System.out.println(Thread.currentThread().getContextClassLoader());
       interpreter.setClassLoader(Thread.currentThread().getContextClassLoader());
       //interpreter.eval (new java.io.InputStreamReader (url.openStream()), new NameSpace (this.rootContextName), this.rootContextName);
-      interpreter.eval (new java.io.InputStreamReader (url.openStream()));
+      InputStream is = url.openStream();
+      try{
+          interpreter.eval (new java.io.InputStreamReader (is));
+      } finally {
+          try{
+              is.close();
+          } catch(Exception e){}
+      }
       //interpreter.source (url.getFile(), new bsh.NameSpace(this.rootContextName));
       
       script = (ScriptPlugin)interpreter.getInterface(ScriptPlugin.class);
Index: console/src/main/org/jboss/console/plugins/monitor/ManageSnapshotServlet.java
===================================================================
--- console/src/main/org/jboss/console/plugins/monitor/ManageSnapshotServlet.java	(revision 113831)
+++ console/src/main/org/jboss/console/plugins/monitor/ManageSnapshotServlet.java	(working copy)
@@ -218,8 +218,11 @@
          );
          resp.setContentType("image/png");
          OutputStream out = resp.getOutputStream();
-         ChartUtilities.writeChartAsPNG(out, chart, 400, 300);
-         out.close();
+         try{
+             ChartUtilities.writeChartAsPNG(out, chart, 400, 300);
+         } finally {
+             out.close();
+         }
          return;
       }
       error("Unknown Action", req, resp);
Index: console/src/main/org/jboss/console/manager/DeploymentFileRepository.java
===================================================================
--- console/src/main/org/jboss/console/manager/DeploymentFileRepository.java	(revision 113831)
+++ console/src/main/org/jboss/console/manager/DeploymentFileRepository.java	(working copy)
@@ -83,8 +83,12 @@
       
       File tmpfile = new File(dir, filename + ".tmp");
       PrintWriter writer = new PrintWriter(new FileOutputStream(tmpfile));
-      writer.write(data);
-      writer.close();
+      try{
+          writer.write(data);
+      }finally{
+          if(writer!=null)
+              writer.close();
+      }
       
       if (file.exists() && noHotDeploy)
       {
Index: console/src/main/org/jboss/console/twiddle/Twiddle.java
===================================================================
--- console/src/main/org/jboss/console/twiddle/Twiddle.java	(revision 113831)
+++ console/src/main/org/jboss/console/twiddle/Twiddle.java	(working copy)
@@ -376,8 +376,13 @@
       InputStream input = cmdProps.openStream();
       log.debug("command proto type properties: " + cmdProps);
       Properties props = new Properties();
-      props.load(input);
-      input.close();
+      try{
+          props.load(input);
+      }finally{
+          try{
+              input.close();
+          }catch(Exception e){}
+      }
 
       Iterator iter = props.keySet().iterator();
       while (iter.hasNext())
Index: mbeans/src/main/org/jboss/mx/persistence/ObjectStreamPersistenceManager.java
===================================================================
--- mbeans/src/main/org/jboss/mx/persistence/ObjectStreamPersistenceManager.java	(revision 113831)
+++ mbeans/src/main/org/jboss/mx/persistence/ObjectStreamPersistenceManager.java	(working copy)
@@ -102,13 +102,13 @@
       {
          return;
       }
-
+      FileInputStream fis = null;
+      ObjectInputStream ois = null;
       try
       {
-         FileInputStream fis = new FileInputStream(storeFile);
-         ObjectInputStream ois = new ObjectInputStream(fis);
+         fis = new FileInputStream(storeFile);
+         ois = new ObjectInputStream(fis);
          ModelMBeanInfo storeMetadata = (ModelMBeanInfo) ois.readObject();
-         ois.close();
          log.debug("metadata deserialized");
          if( log.isTraceEnabled() )
             log.trace("storeMetadata: "+storeMetadata);
@@ -117,6 +117,16 @@
       catch (Exception e)
       {
          log.error("Error loading MBean state", e);
+      } finally{
+          if(ois!=null)
+              try{
+                  ois.close();
+              }catch(Exception e){}
+          
+          if(fis!=null)
+              try{
+                  fis.close();
+              }catch(Exception e){}
       }
    }
 
@@ -145,16 +155,28 @@
          return;
       }
 
+      FileOutputStream fos = null;
+      ObjectOutputStream oos = null;
       try
       {
          log.debug("Storing to file: "+storeFile.getAbsolutePath());
-         FileOutputStream fos = new FileOutputStream(storeFile);
-         ObjectOutputStream oos = new ObjectOutputStream(fos);
+         fos = new FileOutputStream(storeFile);
+         oos = new ObjectOutputStream(fos);
          oos.writeObject(metadata);
       }
       catch (IOException e)
       {
          throw new MBeanException(e, "Error in persisting MBean.");
+      } finally{
+          if(oos!=null)
+              try{
+                  oos.close();
+              }catch(Exception e){}
+          
+          if(fos!=null)
+              try{
+                  fos.close();
+              }catch(Exception e){}
       }
    }
 
Index: mbeans/src/main/org/jboss/mx/persistence/MBeanInfoOdb.java
===================================================================
--- mbeans/src/main/org/jboss/mx/persistence/MBeanInfoOdb.java	(revision 113831)
+++ mbeans/src/main/org/jboss/mx/persistence/MBeanInfoOdb.java	(working copy)
@@ -54,20 +54,48 @@
    protected void store(MBeanInfo metadata, File location) throws IOException
    {
        location.createNewFile();
-       FileOutputStream fos = new FileOutputStream(location);
-       ObjectOutputStream oos = new ObjectOutputStream(fos);
-       oos.writeObject(metadata);
+       FileOutputStream fos = null;
+       ObjectOutputStream oos = null;
+       try{
+           fos = new FileOutputStream(location);
+           oos = new ObjectOutputStream(fos);
+           oos.writeObject(metadata);
+           
+       }finally{
+           if(oos!=null)
+               try{
+                   oos.close();
+               }catch(Exception e){}
+           
+           if(fos!=null)
+               try{
+                   fos.close();
+               }catch(Exception e){}
+       }
    }
    
    protected MBeanInfo load(File location) 
      throws IOException, FileNotFoundException, ClassNotFoundException
    {
        logger().info("Loading mbean info from location: " + location.getAbsolutePath());
-       FileInputStream fis = new FileInputStream(location);
-       ObjectInputStream ois = new ObjectInputStream(fis);
-       MBeanInfo obj = (MBeanInfo) ois.readObject();
-       ois.close();
-       return obj;
+       FileInputStream fis = null;
+       ObjectInputStream ois = null;
+       try{
+           fis = new FileInputStream(location);
+           ois = new ObjectInputStream(fis);
+           MBeanInfo obj = (MBeanInfo) ois.readObject();
+           return obj;
+       }finally{
+           if(ois!=null)
+               try{
+                   ois.close();
+               }catch(Exception e){}
+           
+           if(fis!=null)
+               try{
+                   fis.close();
+               }catch(Exception e){}
+       }
    }
 
    protected Logger logger()
Index: security/src/main/org/jboss/security/plugins/JaasSecurityDomain.java
===================================================================
--- security/src/main/org/jboss/security/plugins/JaasSecurityDomain.java	(revision 113831)
+++ security/src/main/org/jboss/security/plugins/JaasSecurityDomain.java	(working copy)
@@ -1042,11 +1042,17 @@
          {
             is = keyStoreURL.openStream();
          }
-         keyStore.load(is, keyStorePassword);
+         try{
+             keyStore.load(is, keyStorePassword);
+         }finally{
+             try{
+                 is.close();
+             } catch(Exception e){}
+         }
          if (keyStoreAlias != null && !keyStore.isKeyEntry(keyStoreAlias))
          {
             throw new IOException("Cannot find key entry with alias " + keyStoreAlias + " in the keyStore");
-         }
+         } 
          String algorithm = null;
          if (keyMgrFactoryAlgorithm != null)
             algorithm = keyMgrFactoryAlgorithm;
@@ -1087,7 +1093,13 @@
          {
             is = trustStoreURL.openStream();
          }
-         trustStore.load(is, trustStorePassword);
+         try{
+             trustStore.load(is, trustStorePassword);
+         }finally{
+             try{
+                 is.close();
+             } catch(Exception e){}
+         }
          String algorithm = null;
          if (trustMgrFactoryAlgorithm != null)
             algorithm = trustMgrFactoryAlgorithm;
Index: security/src/main/org/jboss/security/integration/password/KeyStoreUtil.java
===================================================================
--- security/src/main/org/jboss/security/integration/password/KeyStoreUtil.java	(revision 113831)
+++ security/src/main/org/jboss/security/integration/password/KeyStoreUtil.java	(working copy)
@@ -52,8 +52,14 @@
    {
       KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
       ks.load(null, storePass); //creates an empty keystore 
-      
-      ks.store(new FileOutputStream(new File(path)), storePass);
+      FileOutputStream fis = new FileOutputStream(new File(path));
+      try{
+          ks.store(fis, storePass);
+      }finally{
+          try{
+              fis.close();
+          }catch(Exception e){}
+      }
       System.out.println("Keystore created");
    }
    
@@ -72,7 +78,13 @@
       
       File file = new File(fileURL);
       FileInputStream fis = new FileInputStream(file);
-      return getKeyStore(fis,storePass);
+      try{
+          return getKeyStore(fis,storePass);
+      } finally {
+          try{
+              fis.close();
+          } catch(Exception e){}
+      }
    }
    
    /**
@@ -87,8 +99,14 @@
    {
       if(url == null)
          throw new IllegalArgumentException("url is null");
-      
-      return getKeyStore(url.openStream(), storePass);
+      InputStream is = url.openStream();
+      try{
+          return getKeyStore(is, storePass);
+      }finally{
+          try{
+              is.close();
+          }catch(Exception e){}
+      }
    }
    
    /**
@@ -106,7 +124,13 @@
       if(ksStream == null)
          throw new IllegalArgumentException("InputStream for the KeyStore is null");
       KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
-      ks.load(ksStream, storePass);
+      try{
+          ks.load(ksStream, storePass);
+      }finally{
+          try{
+              ksStream.close();
+          }catch(Exception e){}
+      }
       return ks;
    }
    
Index: security/src/main/org/jboss/security/integration/password/PasswordMaskManagement.java
===================================================================
--- security/src/main/org/jboss/security/integration/password/PasswordMaskManagement.java	(revision 113831)
+++ security/src/main/org/jboss/security/integration/password/PasswordMaskManagement.java	(working copy)
@@ -367,9 +367,13 @@
          URL url = new URL(this.passwordEncryptedFileName);
          File file = new File(url.toString());
          faos = new FileOutputStream(file);
-         faos.write(data);
-         faos.flush();
-         faos.close(); 
+         try{
+             faos.write(data);
+         } finally {
+             try{
+                 faos.close();
+             }catch(Exception e){}
+         }
       }
       catch(Exception e)
       {
@@ -379,10 +383,14 @@
       finally
       {
          if(faos == null)
-            throw new RuntimeException("File Output Stream is null"); 
-         faos.write(data);
-         faos.flush();
-         faos.close();
+            throw new RuntimeException("File Output Stream is null");
+         try{
+             faos.write(data);
+         } finally {
+             try{
+                 faos.close();
+             }catch(Exception e){}
+         }
       }  
    }
 }
\ No newline at end of file
Index: security/src/main/org/jboss/security/deployers/AclConfigParsingDeployer.java
===================================================================
--- security/src/main/org/jboss/security/deployers/AclConfigParsingDeployer.java	(revision 113831)
+++ security/src/main/org/jboss/security/deployers/AclConfigParsingDeployer.java	(working copy)
@@ -21,6 +21,8 @@
  */
 package org.jboss.security.deployers;
 
+import java.io.InputStream;
+
 import org.jboss.deployers.vfs.spi.deployer.SchemaResolverDeployer;
 import org.jboss.security.acl.config.ACLConfiguration;
 import org.jboss.security.acl.config.ACLConfigurationFactory;
@@ -43,6 +45,13 @@
    @Override
    protected ACLConfiguration parse(VirtualFile file) throws Exception
    {
-      return ACLConfigurationFactory.getConfiguration(file.openStream());
+       InputStream is = file.openStream();
+       try{
+           return ACLConfigurationFactory.getConfiguration(is);
+       }finally{
+           try{
+               is.close();
+           }catch(Exception e){}
+       }
    } 
 }
\ No newline at end of file
Index: hornetq-int/src/main/java/org/jboss/as/integration/hornetq/deployers/HornetQConfigParserDeployer.java
===================================================================
--- hornetq-int/src/main/java/org/jboss/as/integration/hornetq/deployers/HornetQConfigParserDeployer.java	(revision 113831)
+++ hornetq-int/src/main/java/org/jboss/as/integration/hornetq/deployers/HornetQConfigParserDeployer.java	(working copy)
@@ -78,12 +78,13 @@
          return config;
       } finally
       {
-         try
-         {
-            deploymentStream.close();
-         } catch (Exception ignored)
-         {
-         }
+          if(deploymentStream!=null)
+             try
+             {
+                deploymentStream.close();
+             } catch (Exception ignored)
+             {
+             }
       }
    }
 }
Index: hornetq-int/src/main/java/org/jboss/as/integration/hornetq/deployers/HornetQJMSParserDeployer.java
===================================================================
--- hornetq-int/src/main/java/org/jboss/as/integration/hornetq/deployers/HornetQJMSParserDeployer.java	(revision 113831)
+++ hornetq-int/src/main/java/org/jboss/as/integration/hornetq/deployers/HornetQJMSParserDeployer.java	(working copy)
@@ -79,12 +79,13 @@
             return config;
         } finally
         {
-            try
-            {
-                deploymentStream.close();
-            } catch (Exception ignored)
-            {
-            }
+            if(deploymentStream!=null)
+                try
+                {
+                    deploymentStream.close();
+                } catch (Exception ignored)
+                {
+                }
         }
     }
     
Index: management/src/main/org/jboss/management/j2ee/J2EEDeployedObject.java
===================================================================
--- management/src/main/org/jboss/management/j2ee/J2EEDeployedObject.java	(revision 113831)
+++ management/src/main/org/jboss/management/j2ee/J2EEDeployedObject.java	(working copy)
@@ -99,19 +99,21 @@
       String lDD = null;
       Reader lInput = null;
       StringWriter lOutput = null;
+      InputStream lStream = null;
       try
       {
          if (descriptor == null)
          {
             // Use the baseJarUrl as the descriptor
-            lInput = new InputStreamReader(baseJarUrl.openStream());
+            lStream = baseJarUrl.openStream();
+            lInput = new InputStreamReader(lStream);
          }
          else
          {
             // Look for an embedded descriptor
             log.debug("File: " + baseJarUrl + ", descriptor: " + descriptor);
             ClassLoader localCl = new URLClassLoader(new URL[]{baseJarUrl});
-            InputStream lStream = localCl.getResourceAsStream(descriptor);
+            lStream = localCl.getResourceAsStream(descriptor);
             if (lStream == null)
             {
                // If DD not found then return a null indicating the file is not available
@@ -134,16 +136,26 @@
       }
       finally
       {
-         if (lInput != null)
-         {
-            try
-            {
-               lInput.close();
-            }
-            catch (Exception e)
-            {
-            }
-         }
+          if (lInput != null)
+          {
+             try
+             {
+                lInput.close();
+             }
+             catch (Exception e)
+             {
+             }
+          }
+          if (lStream != null)
+          {
+             try
+             {
+                 lStream.close();
+             }
+             catch (Exception e)
+             {
+             }
+          }
          if (lOutput != null)
          {
             try
