* findbugs: mostly stream closure fixes in router, apps, core

This commit is contained in:
dg2-new
2014-04-21 10:54:52 +00:00
parent b9491b269b
commit b84682fdc9
13 changed files with 46 additions and 23 deletions

View File

@ -135,7 +135,7 @@ class PeerConnectionOut implements Runnable
nm = null; nm = null;
} }
if (m == null && nm != null) if (nm != null)
{ {
m = nm; m = nm;
//SimpleTimer.getInstance().removeEvent(nm.expireEvent); //SimpleTimer.getInstance().removeEvent(nm.expireEvent);

View File

@ -1415,6 +1415,8 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
//_log.error(getPrefix() + "Error generating keys to out", ioe); //_log.error(getPrefix() + "Error generating keys to out", ioe);
//notifyEvent("genkeysResult", "error"); //notifyEvent("genkeysResult", "error");
return; return;
} finally {
if(pubdest != null) try { pubdest.close(); } catch(IOException ioe) {}
} }
} else if (args.length != 1) { } else if (args.length != 1) {
l.log("genkeys <privkeyfile> [<pubkeyfile>]\n" + l.log("genkeys <privkeyfile> [<pubkeyfile>]\n" +

View File

@ -94,7 +94,8 @@ public class IrcInboundFilter implements Runnable {
} catch (RuntimeException re) { } catch (RuntimeException re) {
_log.error("Error filtering inbound data", re); _log.error("Error filtering inbound data", re);
} finally { } finally {
try { local.close(); } catch (IOException e) {} try { in.close(); } catch (IOException e) {}
try { local.close(); } catch(IOException e) {}
} }
if(_log.shouldLog(Log.DEBUG)) if(_log.shouldLog(Log.DEBUG))
_log.debug("IrcInboundFilter: Done."); _log.debug("IrcInboundFilter: Done.");

View File

@ -468,8 +468,10 @@ public class SOCKS5Server extends SOCKSServer {
if (dest == null) if (dest == null)
throw new SOCKSException("Outproxy not found"); throw new SOCKSException("Outproxy not found");
I2PSocket destSock = tun.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(proxy), proxyOpts); I2PSocket destSock = tun.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(proxy), proxyOpts);
DataOutputStream out = null;
DataInputStream in = null;
try { try {
DataOutputStream out = new DataOutputStream(destSock.getOutputStream()); out = new DataOutputStream(destSock.getOutputStream());
boolean authAvail = Boolean.parseBoolean(props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH)); boolean authAvail = Boolean.parseBoolean(props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH));
String configUser = null; String configUser = null;
String configPW = null; String configPW = null;
@ -497,7 +499,7 @@ public class SOCKS5Server extends SOCKSServer {
out.flush(); out.flush();
// read init reply // read init reply
DataInputStream in = new DataInputStream(destSock.getInputStream()); in = new DataInputStream(destSock.getInputStream());
// is this right or should we not try to do 5-to-4 conversion? // is this right or should we not try to do 5-to-4 conversion?
int hisVersion = in.readByte(); int hisVersion = in.readByte();
if (hisVersion != SOCKS_VERSION_5 /* && addrtype == AddressType.DOMAINNAME */ ) if (hisVersion != SOCKS_VERSION_5 /* && addrtype == AddressType.DOMAINNAME */ )
@ -573,6 +575,8 @@ public class SOCKS5Server extends SOCKSServer {
throw new SOCKSException("Outproxy rejected request, response = " + reply); throw new SOCKSException("Outproxy rejected request, response = " + reply);
// throw away the address in the response // throw away the address in the response
// todo pass the response through? // todo pass the response through?
out.close();
in.close();
} catch (IOException e) { } catch (IOException e) {
try { destSock.close(); } catch (IOException ioe) {} try { destSock.close(); } catch (IOException ioe) {}
throw e; throw e;

View File

@ -168,9 +168,10 @@ public class LogsHelper extends HelperBase {
private static String readTextFile(File f, int maxNumLines) { private static String readTextFile(File f, int maxNumLines) {
if (!f.exists()) return null; if (!f.exists()) return null;
FileInputStream fis = null; FileInputStream fis = null;
BufferedReader in = null;
try { try {
fis = new FileInputStream(f); fis = new FileInputStream(f);
BufferedReader in = new BufferedReader(new InputStreamReader(fis)); in = new BufferedReader(new InputStreamReader(fis));
List<String> lines = new ArrayList<String>(maxNumLines); List<String> lines = new ArrayList<String>(maxNumLines);
String line = null; String line = null;
while ( (line = in.readLine()) != null) { while ( (line = in.readLine()) != null) {
@ -186,7 +187,7 @@ public class LogsHelper extends HelperBase {
} catch (IOException ioe) { } catch (IOException ioe) {
return null; return null;
} finally { } finally {
if (fis != null) try { fis.close(); } catch (IOException ioe) {} if (in != null) try { in.close(); } catch (IOException ioe) {}
} }
} }
} }

View File

@ -81,7 +81,7 @@ public class SAMStreamSend {
public void streamClosedReceived(String result, int id, String message) { public void streamClosedReceived(String result, int id, String message) {
Sender sender = null; Sender sender = null;
synchronized (_remotePeers) { synchronized (_remotePeers) {
sender = _remotePeers.remove(new Integer(id)); sender = _remotePeers.remove(Integer.valueOf(id));
} }
if (sender != null) { if (sender != null) {
sender.closed(); sender.closed();
@ -171,7 +171,7 @@ public class SAMStreamSend {
_remoteDestination = new String(dest, 0, read); _remoteDestination = new String(dest, 0, read);
synchronized (_remotePeers) { synchronized (_remotePeers) {
_connectionId = _remotePeers.size() + 1; _connectionId = _remotePeers.size() + 1;
_remotePeers.put(new Integer(_connectionId), Sender.this); _remotePeers.put(Integer.valueOf(_connectionId), Sender.this);
} }
_context.statManager().createRateStat("send." + _connectionId + ".totalSent", "Data size sent", "swarm", new long[] { 30*1000, 60*1000, 5*60*1000 }); _context.statManager().createRateStat("send." + _connectionId + ".totalSent", "Data size sent", "swarm", new long[] { 30*1000, 60*1000, 5*60*1000 });

View File

@ -83,7 +83,7 @@ public class SAMStreamSink {
public void streamClosedReceived(String result, int id, String message) { public void streamClosedReceived(String result, int id, String message) {
Sink sink = null; Sink sink = null;
synchronized (_remotePeers) { synchronized (_remotePeers) {
sink = _remotePeers.remove(new Integer(id)); sink = _remotePeers.remove(Integer.valueOf(id));
} }
if (sink != null) { if (sink != null) {
sink.closed(); sink.closed();
@ -96,7 +96,7 @@ public class SAMStreamSink {
public void streamDataReceived(int id, byte data[], int offset, int length) { public void streamDataReceived(int id, byte data[], int offset, int length) {
Sink sink = null; Sink sink = null;
synchronized (_remotePeers) { synchronized (_remotePeers) {
sink = _remotePeers.get(new Integer(id)); sink = _remotePeers.get(Integer.valueOf(id));
} }
if (sink != null) { if (sink != null) {
sink.received(data, offset, length); sink.received(data, offset, length);
@ -111,7 +111,7 @@ public class SAMStreamSink {
try { try {
Sink sink = new Sink(id, dest); Sink sink = new Sink(id, dest);
synchronized (_remotePeers) { synchronized (_remotePeers) {
_remotePeers.put(new Integer(id), sink); _remotePeers.put(Integer.valueOf(id), sink);
} }
} catch (IOException ioe) { } catch (IOException ioe) {
_log.error("Error creating a new sink", ioe); _log.error("Error creating a new sink", ioe);
@ -169,15 +169,17 @@ public class SAMStreamSink {
} }
private boolean writeDest(String dest) { private boolean writeDest(String dest) {
FileOutputStream fos = null;
try { try {
FileOutputStream fos = new FileOutputStream(_destFile); fos = new FileOutputStream(_destFile);
fos.write(dest.getBytes()); fos.write(dest.getBytes());
fos.close();
return true;
} catch (Exception e) { } catch (Exception e) {
_log.error("Error writing to " + _destFile, e); _log.error("Error writing to " + _destFile, e);
return false; return false;
} finally {
if(fos != null) try { fos.close(); } catch(IOException ioe) {}
} }
return true;
} }
private class Sink { private class Sink {

View File

@ -27,6 +27,7 @@ import i2p.susi.debug.Debug;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
@ -91,10 +92,14 @@ public class Config {
{ {
// DEBUG level logging won't work here since we haven't loaded the config yet... // DEBUG level logging won't work here since we haven't loaded the config yet...
properties = new Properties(); properties = new Properties();
InputStream iv = null;
try { try {
properties.load( Config.class.getResourceAsStream( "/susimail.properties" ) ); iv = Config.class.getResourceAsStream("/susimail.properties");
properties.load(iv);
} catch (Exception e) { } catch (Exception e) {
Debug.debug(Debug.ERROR, "Could not open WEB-INF/classes/susimail.properties (possibly in jar), reason: " + e); Debug.debug(Debug.ERROR, "Could not open WEB-INF/classes/susimail.properties (possibly in jar), reason: " + e);
} finally {
if(iv != null) try { iv.close(); } catch(IOException ioe) {}
} }
try { try {
File cfg = new File(I2PAppContext.getGlobalContext().getConfigDir(), "susimail.config"); File cfg = new File(I2PAppContext.getGlobalContext().getConfigDir(), "susimail.config");

View File

@ -39,11 +39,12 @@ public class CertUtil {
*/ */
public static boolean saveCert(Certificate cert, File file) { public static boolean saveCert(Certificate cert, File file) {
OutputStream os = null; OutputStream os = null;
PrintWriter wr = null;
try { try {
// Get the encoded form which is suitable for exporting // Get the encoded form which is suitable for exporting
byte[] buf = cert.getEncoded(); byte[] buf = cert.getEncoded();
os = new SecureFileOutputStream(file); os = new SecureFileOutputStream(file);
PrintWriter wr = new PrintWriter(os); wr = new PrintWriter(os);
wr.println("-----BEGIN CERTIFICATE-----"); wr.println("-----BEGIN CERTIFICATE-----");
String b64 = Base64.encode(buf, true); // true = use standard alphabet String b64 = Base64.encode(buf, true); // true = use standard alphabet
for (int i = 0; i < b64.length(); i += LINE_LENGTH) { for (int i = 0; i < b64.length(); i += LINE_LENGTH) {

View File

@ -355,9 +355,10 @@ public class FileUtil {
File f = new File(filename); File f = new File(filename);
if (!f.exists()) return null; if (!f.exists()) return null;
FileInputStream fis = null; FileInputStream fis = null;
BufferedReader in = null;
try { try {
fis = new FileInputStream(f); fis = new FileInputStream(f);
BufferedReader in = new BufferedReader(new InputStreamReader(fis, "UTF-8")); in = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
List<String> lines = new ArrayList<String>(maxNumLines > 0 ? maxNumLines : 64); List<String> lines = new ArrayList<String>(maxNumLines > 0 ? maxNumLines : 64);
String line = null; String line = null;
while ( (line = in.readLine()) != null) { while ( (line = in.readLine()) != null) {
@ -377,7 +378,7 @@ public class FileUtil {
} catch (IOException ioe) { } catch (IOException ioe) {
return null; return null;
} finally { } finally {
if (fis != null) try { fis.close(); } catch (IOException ioe) {} if (in != null) try { in.close(); } catch (IOException ioe) {}
} }
} }

View File

@ -391,14 +391,16 @@ public class TranslateReader extends FilterReader {
} }
private static void test(String file) throws IOException { private static void test(String file) throws IOException {
FileInputStream fio = new FileInputStream(file);
TranslateReader r = new TranslateReader(I2PAppContext.getGlobalContext(), TranslateReader r = new TranslateReader(I2PAppContext.getGlobalContext(),
"net.i2p.router.web.messages", "net.i2p.router.web.messages",
new FileInputStream(file)); fio);
int c; int c;
while ((c = r.read()) >= 0) { while ((c = r.read()) >= 0) {
System.out.print((char)c); System.out.print((char)c);
} }
System.out.flush(); System.out.flush();
r.close();
} }
/** @param files ignore 0 */ /** @param files ignore 0 */

View File

@ -1,3 +1,6 @@
2014-04-21 dg
* findbugs: mostly stream closure fixes in router, apps, core
2014-04-20 zzz 2014-04-20 zzz
* SusiMail: * SusiMail:
- Implement extensive pipelining in POP3 for a big speedup - Implement extensive pipelining in POP3 for a big speedup

View File

@ -1314,9 +1314,10 @@ public class Router implements RouterClock.ClockShiftListener {
return; return;
// this is similar to FileUtil.readTextFile() but we can't use any I2P classes here // this is similar to FileUtil.readTextFile() but we can't use any I2P classes here
FileInputStream fis = null; FileInputStream fis = null;
BufferedReader in = null;
try { try {
fis = new FileInputStream(deleteFile); fis = new FileInputStream(deleteFile);
BufferedReader in = new BufferedReader(new InputStreamReader(fis, "UTF-8")); in = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
String line; String line;
while ( (line = in.readLine()) != null) { while ( (line = in.readLine()) != null) {
String fl = line.trim(); String fl = line.trim();
@ -1331,9 +1332,9 @@ public class Router implements RouterClock.ClockShiftListener {
System.out.println("INFO: File [" + fl + "] deleted"); System.out.println("INFO: File [" + fl + "] deleted");
} }
} }
} catch (IOException ioe) { } catch (IOException ioe) {}
} finally { finally {
if (fis != null) try { fis.close(); } catch (IOException ioe) {} if (in != null) try { in.close(); } catch(IOException ioe) {}
if (deleteFile.delete()) if (deleteFile.delete())
System.out.println("INFO: File [" + DELETE_FILE + "] deleted"); System.out.println("INFO: File [" + DELETE_FILE + "] deleted");
} }