Commit a29dd6cc authored by newt's avatar newt Committed by Commit bot

[Android] Fix findbugs errors.

These were failing on Android Builder (dbg) FYI bot.

BUG=409152
TBR=qinmin@chromium.org

Review URL: https://codereview.chromium.org/522943003

Cr-Commit-Position: refs/heads/master@{#293206}
parent 3d377a4a
......@@ -56,7 +56,7 @@ public class AwBrowserContext {
public HttpAuthDatabase getHttpAuthDatabase(Context context) {
if (mHttpAuthDatabase == null) {
mHttpAuthDatabase = new HttpAuthDatabase(context, HTTP_AUTH_DATABASE_FILE);
mHttpAuthDatabase = HttpAuthDatabase.newInstance(context, HTTP_AUTH_DATABASE_FILE);
}
return mHttpAuthDatabase;
}
......
......@@ -55,21 +55,26 @@ public class HttpAuthDatabase {
private final Object mInitializedLock = new Object();
/**
* Create an instance of HttpAuthDatabase for the named file, and kick-off background
* initialization of that database.
* Creates and returns an instance of HttpAuthDatabase for the named file, and kicks-off
* background initialization of that database.
*
* @param context the Context to use for opening the database
* @param databaseFile Name of the file to be initialized.
*/
public HttpAuthDatabase(final Context context, final String databaseFile) {
public static HttpAuthDatabase newInstance(final Context context, final String databaseFile) {
final HttpAuthDatabase httpAuthDatabase = new HttpAuthDatabase();
new Thread() {
@Override
public void run() {
initOnBackgroundThread(context, databaseFile);
httpAuthDatabase.initOnBackgroundThread(context, databaseFile);
}
}.start();
return httpAuthDatabase;
}
// Prevent instantiation. Callers should use newInstance().
private HttpAuthDatabase() {}
/**
* Initializes the databases and notifies any callers waiting on waitForInit.
*
......
......@@ -32,7 +32,7 @@ public class HttpAuthDatabaseTest extends AndroidTestCase {
@SmallTest
@Feature({"AndroidWebView"})
public void testAccessHttpAuthUsernamePassword() throws Exception {
HttpAuthDatabase instance = new HttpAuthDatabase(getContext(), TEST_DATABASE);
HttpAuthDatabase instance = HttpAuthDatabase.newInstance(getContext(), TEST_DATABASE);
String host = "http://localhost:8080";
String realm = "testrealm";
......
......@@ -8,6 +8,7 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.Key;
import java.security.SecureRandom;
......@@ -153,7 +154,10 @@ public class CipherFactory {
try {
seed = mRandomNumberProvider.getBytes(NUM_BYTES);
iv = mRandomNumberProvider.getBytes(NUM_BYTES);
} catch (Exception e) {
} catch (IOException e) {
Log.e(TAG, "Couldn't get generator data.");
return null;
} catch (GeneralSecurityException e) {
Log.e(TAG, "Couldn't get generator data.");
return null;
}
......
......@@ -194,7 +194,7 @@ public class Shell extends LinearLayout {
* @return The sanitized URL.
*/
public static String sanitizeUrl(String url) {
if (url == null) return url;
if (url == null) return null;
if (url.startsWith("www.") || url.indexOf(":") == -1) url = "http://" + url;
return url;
}
......
......@@ -205,7 +205,6 @@ public class MediaDrmBridge {
if (MediaCrypto.isCryptoSchemeSupported(mSchemeUUID)) {
final byte[] mediaCryptoSession = mMediaCryptoSession.array();
mMediaCrypto = new MediaCrypto(mSchemeUUID, mediaCryptoSession);
assert mMediaCrypto != null;
Log.d(TAG, "MediaCrypto successfully created!");
mSessionIds.put(mMediaCryptoSession, INVALID_SESSION_ID);
// Notify the native code that MediaCrypto is ready.
......
......@@ -23,15 +23,15 @@ public class NetStringUtil {
* Attempts to convert text in a given character set to a Unicode string.
* Returns null on failure.
* @param text ByteBuffer containing the character array to convert.
* @param charset Character set it's in encoded in.
* @param charsetName Character set it's in encoded in.
* @return: Unicode string on success, null on failure.
*/
@CalledByNative
private static String convertToUnicode(
ByteBuffer text,
String charset_name) {
String charsetName) {
try {
Charset charset = Charset.forName(charset_name);
Charset charset = Charset.forName(charsetName);
CharsetDecoder decoder = charset.newDecoder();
// On invalid characters, this will throw an exception.
return decoder.decode(text).toString();
......@@ -44,16 +44,15 @@ public class NetStringUtil {
* Attempts to convert text in a given character set to a Unicode string,
* and normalize it. Returns null on failure.
* @param text ByteBuffer containing the character array to convert.
* @param charset Character set it's in encoded in.
* @param charsetName Character set it's in encoded in.
* @return: Unicode string on success, null on failure.
*/
@CalledByNative
private static String convertToUnicodeAndNormalize(
ByteBuffer text,
String charset_name) {
String unicodeString = convertToUnicode(text, charset_name);
if (unicodeString == null)
return unicodeString;
String charsetName) {
String unicodeString = convertToUnicode(text, charsetName);
if (unicodeString == null) return null;
return Normalizer.normalize(unicodeString, Normalizer.Form.NFC);
}
......@@ -62,15 +61,15 @@ public class NetStringUtil {
* characters are replaced with U+FFFD. Returns null if the character set
* is not recognized.
* @param text ByteBuffer containing the character array to convert.
* @param charset Character set it's in encoded in.
* @param charsetName Character set it's in encoded in.
* @return: Unicode string on success, null on failure.
*/
@CalledByNative
private static String convertToUnicodeWithSubstitutions(
ByteBuffer text,
String charset_name) {
String charsetName) {
try {
Charset charset = Charset.forName(charset_name);
Charset charset = Charset.forName(charsetName);
// TODO(mmenke): Investigate if Charset.decode() can be used
// instead. The question is whether it uses the proper replace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment