* 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;
}
if (m == null && nm != null)
if (nm != null)
{
m = nm;
//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);
//notifyEvent("genkeysResult", "error");
return;
} finally {
if(pubdest != null) try { pubdest.close(); } catch(IOException ioe) {}
}
} else if (args.length != 1) {
l.log("genkeys <privkeyfile> [<pubkeyfile>]\n" +

View File

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

View File

@ -468,8 +468,10 @@ public class SOCKS5Server extends SOCKSServer {
if (dest == null)
throw new SOCKSException("Outproxy not found");
I2PSocket destSock = tun.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(proxy), proxyOpts);
DataOutputStream out = null;
DataInputStream in = null;
try {
DataOutputStream out = new DataOutputStream(destSock.getOutputStream());
out = new DataOutputStream(destSock.getOutputStream());
boolean authAvail = Boolean.parseBoolean(props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH));
String configUser = null;
String configPW = null;
@ -497,7 +499,7 @@ public class SOCKS5Server extends SOCKSServer {
out.flush();
// 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?
int hisVersion = in.readByte();
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 away the address in the response
// todo pass the response through?
out.close();
in.close();
} catch (IOException e) {
try { destSock.close(); } catch (IOException ioe) {}
throw e;

View File

@ -168,9 +168,10 @@ 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);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
in = new BufferedReader(new InputStreamReader(fis));
List<String> lines = new ArrayList<String>(maxNumLines);
String line = null;
while ( (line = in.readLine()) != null) {
@ -186,7 +187,7 @@ public class LogsHelper extends HelperBase {
} catch (IOException ioe) {
return null;
} 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) {
Sender sender = null;
synchronized (_remotePeers) {
sender = _remotePeers.remove(new Integer(id));
sender = _remotePeers.remove(Integer.valueOf(id));
}
if (sender != null) {
sender.closed();
@ -171,7 +171,7 @@ public class SAMStreamSend {
_remoteDestination = new String(dest, 0, read);
synchronized (_remotePeers) {
_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 });

View File

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

View File

@ -27,6 +27,7 @@ import i2p.susi.debug.Debug;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
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...
properties = new Properties();
InputStream iv = null;
try {
properties.load( Config.class.getResourceAsStream( "/susimail.properties" ) );
iv = Config.class.getResourceAsStream("/susimail.properties");
properties.load(iv);
} catch (Exception 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 {
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) {
OutputStream os = null;
PrintWriter wr = null;
try {
// Get the encoded form which is suitable for exporting
byte[] buf = cert.getEncoded();
os = new SecureFileOutputStream(file);
PrintWriter wr = new PrintWriter(os);
wr = new PrintWriter(os);
wr.println("-----BEGIN CERTIFICATE-----");
String b64 = Base64.encode(buf, true); // true = use standard alphabet
for (int i = 0; i < b64.length(); i += LINE_LENGTH) {

View File

@ -355,9 +355,10 @@ public class FileUtil {
File f = new File(filename);
if (!f.exists()) return null;
FileInputStream fis = null;
BufferedReader in = null;
try {
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);
String line = null;
while ( (line = in.readLine()) != null) {
@ -377,7 +378,7 @@ public class FileUtil {
} catch (IOException ioe) {
return null;
} 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 {
FileInputStream fio = new FileInputStream(file);
TranslateReader r = new TranslateReader(I2PAppContext.getGlobalContext(),
"net.i2p.router.web.messages",
new FileInputStream(file));
fio);
int c;
while ((c = r.read()) >= 0) {
System.out.print((char)c);
}
System.out.flush();
r.close();
}
/** @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
* SusiMail:
- Implement extensive pipelining in POP3 for a big speedup

View File

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