diff --git a/apps/addressbook/java/src/net/metanotion/io/block/BlockFile.java b/apps/addressbook/java/src/net/metanotion/io/block/BlockFile.java
index 4db5e1085f4a55a3c434e6c368b768d8fe470135..2cfec6f62bb6d9caf551a56d4b219d86e026bf8a 100644
--- a/apps/addressbook/java/src/net/metanotion/io/block/BlockFile.java
+++ b/apps/addressbook/java/src/net/metanotion/io/block/BlockFile.java
@@ -144,14 +144,17 @@ public class BlockFile implements Closeable {
 			return;
 		}
 		boolean init = !(new File(args[0])).exists();
+		RAIFile raif = null;
+		BlockFile bf = null;
 		try {
-			RAIFile raif = new RAIFile(new File(args[0]), true, true);
-			BlockFile bf = new BlockFile(raif, init);
+			raif = new RAIFile(new File(args[0]), true, true);
+			bf = new BlockFile(raif, init);
 			bf.bfck(true);
-			bf.close();
-			raif.close();
 		} catch (IOException e) {
 			e.printStackTrace();
+		} finally {
+			if (bf != null) try { bf.close(); } catch (IOException ioe) {}
+			if (raif != null) try { raif.close(); } catch (IOException ioe) {}
 		}
 	}
 
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java
index 03027b4861e3f97233e9d75db571c93cd8e2d3e6..95c5285d519c9e2ea9247af7ed69546cb39e2ba5 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java
@@ -1607,8 +1607,9 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
      */
     private void runRun(String args[], Logging l) {
         if (args.length == 1) {
+            BufferedReader br = null;
             try {
-                BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]), "UTF-8"));
+                br = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]), "UTF-8"));
                 String line;
                 while ((line = br.readLine()) != null) {
                     runCommand(line, l);
@@ -1619,6 +1620,8 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
                 l.log("IO error running the file");
                 _log.error(getPrefix() + "Error running the file", ioe);
                 notifyEvent("runResult", "error");
+            } finally {
+                if (br != null) try { br.close(); } catch (IOException ioe) {}
             }
         } else {
             l.log("run <commandfile>\n" +
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java
index ff7698fe851d409d4be99124e39801e5c5fe51aa..9f858b3c5d0753cb9704954143b70488c2b85cec 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java
@@ -159,7 +159,9 @@ public class I2Ping extends I2PTunnelClientBase {
       }
 
       if (hostListFile != null) {
-            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(hostListFile), "UTF-8"));
+        BufferedReader br = null;
+        try {
+            br = new BufferedReader(new InputStreamReader(new FileInputStream(hostListFile), "UTF-8"));
             String line;
             List<PingHandler> pingHandlers = new ArrayList<PingHandler>();
             int i = 0;
@@ -181,6 +183,9 @@ public class I2Ping extends I2PTunnelClientBase {
             for (Thread t : pingHandlers)
                 t.join();
             return;
+        } finally {
+            if (br != null) try { br.close(); } catch (IOException ioe) {}
+        }
       }
 
       String host = argv[g.getOptind()];
diff --git a/apps/jetty/java/src/net/i2p/jetty/JettyStart.java b/apps/jetty/java/src/net/i2p/jetty/JettyStart.java
index f068a20c08fef51154ec5859fd71dc8f3331258a..cbf54fb5dfb39b08a08d37c7400a595d87dad602 100644
--- a/apps/jetty/java/src/net/i2p/jetty/JettyStart.java
+++ b/apps/jetty/java/src/net/i2p/jetty/JettyStart.java
@@ -1,5 +1,7 @@
 package net.i2p.jetty;
 
+import java.io.IOException;
+
 // Contains code from org.mortbay.xml.XmlConfiguation:
 
 // ========================================================================
@@ -17,6 +19,7 @@ package net.i2p.jetty;
 // ========================================================================
 
 import java.io.InputStream;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -79,14 +82,24 @@ public class JettyStart implements ClientApp {
     public void parseArgs(String[] args) throws Exception {
         Properties properties=new Properties();
         XmlConfiguration last=null;
-        InputStream in = null;
+        Resource r = null;
         for (int i = 0; i < args.length; i++) {
             if (args[i].toLowerCase().endsWith(".properties")) {
-                in = Resource.newResource(args[i]).getInputStream();
-                properties.load(in);
-                in.close();
+                try {
+                    r = Resource.newResource(args[i]);
+                    properties.load(r.getInputStream());
+                } finally {
+                    if (r != null) r.close();
+                }
             } else {
-                XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(args[i]).getURL());
+                URL configUrl;
+                try {
+                    r = Resource.newResource(args[i]);
+                    configUrl = r.getURL();
+                } finally {
+                    if (r != null) r.close();
+                }
+                XmlConfiguration configuration = new XmlConfiguration(configUrl);
                 if (last!=null)
                     configuration.getIdMap().putAll(last.getIdMap());
                 if (properties.size()>0) {
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/LogsHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/LogsHelper.java
index 48a0f518346925b0d193d446e53a97e4cb2aaa82..f14324420c1137c81ce5d964864dd76a178f0bea 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/LogsHelper.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/LogsHelper.java
@@ -173,11 +173,9 @@ public class LogsHelper extends HelperBase {
      */
     private static String readTextFile(File f, int maxNumLines) {
         if (!f.exists()) return null;
-        FileInputStream fis = null;
         BufferedReader in = null;
         try {
-            fis = new FileInputStream(f);
-            in = new BufferedReader(new InputStreamReader(fis));
+            in = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
             List<String> lines = new ArrayList<String>(maxNumLines);
             String line = null;
             while ( (line = in.readLine()) != null) {
diff --git a/apps/sam/java/src/net/i2p/sam/client/SAMStreamSink.java b/apps/sam/java/src/net/i2p/sam/client/SAMStreamSink.java
index 0b67b7abdfebd8be97d283625c06ee4121bd4181..4e1fe063961d008e530aaee4201e101a8afcf1cc 100644
--- a/apps/sam/java/src/net/i2p/sam/client/SAMStreamSink.java
+++ b/apps/sam/java/src/net/i2p/sam/client/SAMStreamSink.java
@@ -243,10 +243,11 @@ public class SAMStreamSink {
         }
 
         public void run() {
+            DatagramSocket dg = null;
             byte[] buf = new byte[32768];
             try {
                 Sink sink = new Sink("FAKE", "FAKEFROM");
-                DatagramSocket dg = new DatagramSocket(V3DGPORT);
+                dg = new DatagramSocket(V3DGPORT);
                 while (true) {
                     DatagramPacket p = new DatagramPacket(buf, 32768);
                     dg.receive(p);
@@ -283,6 +284,8 @@ public class SAMStreamSink {
                 }
             } catch (IOException ioe) {
                 _log.error("DGRcvr", ioe);
+            } finally {
+                if (dg != null) dg.close();
             }
         }
     }
diff --git a/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java b/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java
index aa8f5ef1257ec954209065338d839b037fc1af8b..dabd1ed8e0b47581caf63371fb78317f83960edc 100644
--- a/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java
+++ b/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java
@@ -136,13 +136,15 @@ public class UrlLauncher implements ClientApp {
         long done = System.currentTimeMillis() + MAX_WAIT_TIME;
         for (int i = 0; i < MAX_TRIES; i++) {
             try {
-                Socket test = new Socket();
-                // this will usually fail right away if it's going to fail since it's local
-                test.connect(sa, WAIT_TIME);
-                // it worked
+                Socket test = null;
                 try {
-                   test.close();
-                } catch (IOException ioe) {}
+                    test = new Socket();
+                    // this will usually fail right away if it's going to fail since it's local
+                    test.connect(sa, WAIT_TIME);
+                    // it worked
+                } finally {
+                    if (test != null) try { test.close(); } catch (IOException ioe) {}
+                }
                 // Jetty 6 seems to start the Connector before the
                 // webapp is completely ready
                 try {
diff --git a/core/java/src/freenet/support/CPUInformation/CPUID.java b/core/java/src/freenet/support/CPUInformation/CPUID.java
index 161cdb64dcf1507427d98ccd7f36f9e9affa15f1..ca8c092cd8db3194e817a6a90372f665ad1be2d4 100644
--- a/core/java/src/freenet/support/CPUInformation/CPUID.java
+++ b/core/java/src/freenet/support/CPUInformation/CPUID.java
@@ -551,11 +551,12 @@ public class CPUID {
         URL resource = CPUID.class.getClassLoader().getResource(resourceName);
         if (resource == null)
             return false;
+        InputStream libStream = null;
         File outFile = null;
         FileOutputStream fos = null;
         String filename = getLibraryPrefix() + "jcpuid" + getLibrarySuffix();
         try {
-            InputStream libStream = resource.openStream();
+            libStream = resource.openStream();
             outFile = new File(I2PAppContext.getGlobalContext().getTempDir(), filename);
             fos = new FileOutputStream(outFile);
             DataHelper.copy(libStream, fos);
@@ -580,6 +581,7 @@ public class CPUID {
                 outFile.delete();
             return false;
         } finally {
+            if (libStream != null) try { libStream.close(); } catch (IOException ioe) {}
             if (fos != null) {
                 try { fos.close(); } catch (IOException ioe) {}
             }
diff --git a/core/java/src/net/i2p/client/naming/SingleFileNamingService.java b/core/java/src/net/i2p/client/naming/SingleFileNamingService.java
index 835c3dbdd55f3f3bd235d18697060f6e49e1dddb..acde6e6ed29f07deff394fb71fbfd3ec25683102 100644
--- a/core/java/src/net/i2p/client/naming/SingleFileNamingService.java
+++ b/core/java/src/net/i2p/client/naming/SingleFileNamingService.java
@@ -210,11 +210,13 @@ public class SingleFileNamingService extends NamingService {
             }
             return success;
         } catch (IOException ioe) {
-            if (in != null) try { in.close(); } catch (IOException e) {}
-            if (out != null) try { out.close(); } catch (IOException e) {}
             _log.error("Error adding " + hostname, ioe);
             return false;
-        } finally { releaseWriteLock(); }
+        } finally {
+            if (in != null) try { in.close(); } catch (IOException e) {}
+            if (out != null) try { out.close(); } catch (IOException e) {}
+            releaseWriteLock();
+        }
     }
 
     /** 
@@ -333,11 +335,11 @@ public class SingleFileNamingService extends NamingService {
             }
             return success;
         } catch (IOException ioe) {
-            if (in != null) try { in.close(); } catch (IOException e) {}
-            if (out != null) try { out.close(); } catch (IOException e) {}
             _log.error("Error removing " + hostname, ioe);
             return false;
         } finally {
+            if (in != null) try { in.close(); } catch (IOException e) {}
+            if (out != null) try { out.close(); } catch (IOException e) {}
             releaseWriteLock();
         }
     }
diff --git a/core/java/src/net/i2p/crypto/TrustedUpdate.java b/core/java/src/net/i2p/crypto/TrustedUpdate.java
index 23520942be0fd47e0933d6180b5caf8f55811789..653d427e844b43837072d7551e6a0e86987994f2 100644
--- a/core/java/src/net/i2p/crypto/TrustedUpdate.java
+++ b/core/java/src/net/i2p/crypto/TrustedUpdate.java
@@ -764,13 +764,8 @@ riCe6OlAEiNpcc6mMyIYYWFICbrDFTrDR3wXqwc/Jkcx6L5VVWoagpSzbo3yGhc=
 
             return null;
         } finally {
-            if (bytesToSignInputStream != null)
-                try {
-                    bytesToSignInputStream.close();
-                    fileInputStream.close();
-                } catch (IOException ioe) {
-                }
-
+            if (bytesToSignInputStream != null) try { bytesToSignInputStream.close(); } catch (IOException ioe) {}
+            if (fileInputStream != null) try { fileInputStream.close(); } catch (IOException ioe) {}
         }
 
         FileOutputStream fileOutputStream = null;
diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java
index 0e7dfab112833aad388da0e2bf005c948e4dff67..2f08a0566ba5759755bb6bcac6d58195eebddf0f 100644
--- a/core/java/src/net/i2p/data/DataHelper.java
+++ b/core/java/src/net/i2p/data/DataHelper.java
@@ -494,11 +494,12 @@ public class DataHelper {
      *                                  or a value contains '#' or '\n'
      */
     public static void storeProps(Properties props, File file) throws IOException {
+        FileOutputStream fos = null;
         PrintWriter out = null;
         IllegalArgumentException iae = null;
         File tmpFile = new File(file.getPath() + ".tmp");
         try {
-            FileOutputStream fos = new SecureFileOutputStream(tmpFile);
+            fos = new SecureFileOutputStream(tmpFile);
             out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")));
             out.println("# NOTE: This I2P config file must use UTF-8 encoding");
             for (Map.Entry<Object, Object> entry : props.entrySet()) {
@@ -533,6 +534,7 @@ public class DataHelper {
                 throw new IOException("Failed rename from " + tmpFile + " to " + file);
         } finally {
             if (out != null) out.close();
+            if (fos != null) try { fos.close(); } catch (IOException ioe) {}
         }
         if (iae != null)
             throw iae;
diff --git a/core/java/src/net/i2p/util/NativeBigInteger.java b/core/java/src/net/i2p/util/NativeBigInteger.java
index bbd40912ec35060fa7dae8e12bf2ac998a12e5df..9e043729dedbba385014c67997f2ff0c0ec3b828 100644
--- a/core/java/src/net/i2p/util/NativeBigInteger.java
+++ b/core/java/src/net/i2p/util/NativeBigInteger.java
@@ -1119,11 +1119,12 @@ public class NativeBigInteger extends BigInteger {
             return false;
         }
 
+        InputStream libStream = null;
         File outFile = null;
         FileOutputStream fos = null;
         String filename =  _libPrefix + "jbigi" + _libSuffix;
         try {
-            InputStream libStream = resource.openStream();
+            libStream = resource.openStream();
             outFile = new File(I2PAppContext.getGlobalContext().getTempDir(), filename);
             fos = new FileOutputStream(outFile);
             DataHelper.copy(libStream, fos);
@@ -1143,6 +1144,7 @@ public class NativeBigInteger extends BigInteger {
                 outFile.delete();
             return false;
         } finally {
+            if (libStream != null) try { libStream.close(); } catch (IOException ioe) {}
             if (fos != null) {
                 try { fos.close(); } catch (IOException ioe) {}
             }
diff --git a/core/java/src/net/i2p/util/TranslateReader.java b/core/java/src/net/i2p/util/TranslateReader.java
index 171edd4a87e085519d88ea7546a10fbfd25b7a1a..02eb0a0d68531b8fbe0f728ff4b03ab11833892f 100644
--- a/core/java/src/net/i2p/util/TranslateReader.java
+++ b/core/java/src/net/i2p/util/TranslateReader.java
@@ -395,15 +395,19 @@ public class TranslateReader extends FilterReader {
 
     private static void test(String file) throws IOException {
         FileInputStream fio = new FileInputStream(file);
-        TranslateReader r = new TranslateReader(I2PAppContext.getGlobalContext(),
-                                                "net.i2p.router.web.messages",
-                                                fio);
-        int c;
-        while ((c = r.read()) >= 0) {
-            System.out.print((char)c);
+        TranslateReader r = null;
+        try {
+            r = new TranslateReader(I2PAppContext.getGlobalContext(),
+                                    "net.i2p.router.web.messages",
+                                    fio);
+            int c;
+            while ((c = r.read()) >= 0) {
+                System.out.print((char)c);
+            }
+            System.out.flush();
+        } finally {
+            if (r != null) try { r.close(); } catch (IOException ioe) {}
         }
-        System.out.flush();
-        r.close();
     }
 
     /** @param files ignore 0 */
diff --git a/router/java/src/org/cybergarage/upnp/ssdp/HTTPMUSocket.java b/router/java/src/org/cybergarage/upnp/ssdp/HTTPMUSocket.java
index 657a1e4c943776037fa87eebcb1c5fe2414092a4..34cb29aa7ab30e53a63b44ee1532b5fb518ed05b 100644
--- a/router/java/src/org/cybergarage/upnp/ssdp/HTTPMUSocket.java
+++ b/router/java/src/org/cybergarage/upnp/ssdp/HTTPMUSocket.java
@@ -194,8 +194,8 @@ public class HTTPMUSocket
 
 	public boolean send(String msg, String bindAddr, int bindPort)
 	{
+		MulticastSocket msock = null;
 		try {
-			MulticastSocket msock;
 			if ((bindAddr) != null && (0 < bindPort)) {
 				msock = new MulticastSocket(null);
 				msock.bind(new InetSocketAddress(bindAddr, bindPort));
@@ -206,11 +206,12 @@ public class HTTPMUSocket
 			// Thnaks for Theo Beisch (11/09/04)
 			msock.setTimeToLive(UPnP.getTimeToLive());
 			msock.send(dgmPacket);
-			msock.close();
 		}
 		catch (Exception e) {
 			Debug.warning(e);
 			return false;
+		} finally {
+			if (msock != null) msock.close();
 		}
 		return true;
 	}