mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 05:02:26 -05:00
Close streams on exceptional paths
Addresses FindBugs complaints.
This commit is contained in:
parent
976761e0e5
commit
b53b0d33ba
@ -6,6 +6,7 @@ import android.content.Context;
|
||||
import android.util.Log;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.helper.DomainNameChecker;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
@ -105,12 +106,12 @@ public final class TrustManagerFactory {
|
||||
}
|
||||
|
||||
static {
|
||||
java.io.InputStream fis = null;
|
||||
try {
|
||||
javax.net.ssl.TrustManagerFactory tmf = javax.net.ssl.TrustManagerFactory.getInstance("X509");
|
||||
Application app = K9.app;
|
||||
keyStoreFile = new File(app.getDir("KeyStore", Context.MODE_PRIVATE) + File.separator + "KeyStore.bks");
|
||||
keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
java.io.FileInputStream fis;
|
||||
try {
|
||||
fis = new java.io.FileInputStream(keyStoreFile);
|
||||
} catch (FileNotFoundException e1) {
|
||||
@ -118,9 +119,6 @@ public final class TrustManagerFactory {
|
||||
}
|
||||
try {
|
||||
keyStore.load(fis, "".toCharArray());
|
||||
//if (fis != null) {
|
||||
// fis.close();
|
||||
//}
|
||||
} catch (IOException e) {
|
||||
Log.e(LOG_TAG, "KeyStore IOException while initializing TrustManagerFactory ", e);
|
||||
keyStore = null;
|
||||
@ -154,6 +152,8 @@ public final class TrustManagerFactory {
|
||||
Log.e(LOG_TAG, "Unable to get X509 Trust Manager ", e);
|
||||
} catch (KeyStoreException e) {
|
||||
Log.e(LOG_TAG, "Key Store exception while initializing TrustManagerFactory ", e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(fis);
|
||||
}
|
||||
unsecureTrustManager = new SimpleX509TrustManager();
|
||||
}
|
||||
@ -195,17 +195,18 @@ public final class TrustManagerFactory {
|
||||
}
|
||||
}
|
||||
}
|
||||
java.io.FileOutputStream keyStoreStream;
|
||||
java.io.OutputStream keyStoreStream = null;
|
||||
try {
|
||||
keyStoreStream = new java.io.FileOutputStream(keyStoreFile);
|
||||
keyStore.store(keyStoreStream, "".toCharArray());
|
||||
keyStoreStream.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new CertificateException("Unable to write KeyStore: " + e.getMessage());
|
||||
} catch (CertificateException e) {
|
||||
throw new CertificateException("Unable to write KeyStore: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new CertificateException("Unable to write KeyStore: " + e.getMessage());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(keyStoreStream);
|
||||
}
|
||||
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
@ -11,6 +11,7 @@ import com.fsck.k9.mail.Folder.OpenMode;
|
||||
import com.fsck.k9.mail.filter.EOLConvertingOutputStream;
|
||||
import com.fsck.k9.mail.internet.MimeMessage;
|
||||
import com.fsck.k9.mail.transport.TrustedSocketFactory;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.*;
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
@ -1485,9 +1486,10 @@ public class WebDavStore extends Store {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
String tempText = "";
|
||||
String resultText = "";
|
||||
BufferedReader reader;
|
||||
BufferedReader reader = null;
|
||||
int currentLines = 0;
|
||||
|
||||
try {
|
||||
istream = WebDavHttpClient.getUngzippedContent(entity);
|
||||
|
||||
if (lines != -1) {
|
||||
@ -1505,6 +1507,11 @@ public class WebDavStore extends Store {
|
||||
}
|
||||
|
||||
wdMessage.parse(istream);
|
||||
|
||||
} finally {
|
||||
IOUtils.closeQuietly(reader);
|
||||
IOUtils.closeQuietly(istream);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException iae) {
|
||||
|
Loading…
Reference in New Issue
Block a user