Utils.getBinaryHash() should not catch exceptions
By catching the exception here and returning null, the problem is then passed on further down the line where it is harder to debug. The hash is required wherever this method is called, so this should fail immediately. #699
This commit is contained in:
parent
e77bde2cfa
commit
4907e0b289
@ -145,7 +145,7 @@ public final class Utils {
|
|||||||
InputStream input = null;
|
InputStream input = null;
|
||||||
OutputStream output = null;
|
OutputStream output = null;
|
||||||
try {
|
try {
|
||||||
input = new FileInputStream(inFile);
|
input = new FileInputStream(inFile);
|
||||||
output = new FileOutputStream(outFile);
|
output = new FileOutputStream(outFile);
|
||||||
Utils.copy(input, output);
|
Utils.copy(input, output);
|
||||||
return true;
|
return true;
|
||||||
@ -372,6 +372,11 @@ public final class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the checksum hash of the file {@code apk} using the algorithm in {@code algo}.
|
||||||
|
* {@code apk} must exist on the filesystem and {@code algo} must be supported
|
||||||
|
* by this device, otherwise an {@link IllegalArgumentException} is thrown.
|
||||||
|
*/
|
||||||
public static String getBinaryHash(File apk, String algo) {
|
public static String getBinaryHash(File apk, String algo) {
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
try {
|
try {
|
||||||
@ -387,13 +392,8 @@ public final class Utils {
|
|||||||
|
|
||||||
byte[] mdbytes = md.digest();
|
byte[] mdbytes = md.digest();
|
||||||
return toHexString(mdbytes).toLowerCase(Locale.ENGLISH);
|
return toHexString(mdbytes).toLowerCase(Locale.ENGLISH);
|
||||||
} catch (IOException e) {
|
} catch (IOException | NoSuchAlgorithmException e) {
|
||||||
Log.e(TAG, "Error reading \"" + apk.getAbsolutePath()
|
throw new IllegalArgumentException(e);
|
||||||
+ "\" to compute " + algo + " hash.", e);
|
|
||||||
return null;
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
Log.e(TAG, "Device does not support " + algo + " MessageDisgest algorithm");
|
|
||||||
return null;
|
|
||||||
} finally {
|
} finally {
|
||||||
closeQuietly(fis);
|
closeQuietly(fis);
|
||||||
}
|
}
|
||||||
@ -476,7 +476,7 @@ public final class Utils {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleTag(boolean opening, String tag, Editable output,
|
public void handleTag(boolean opening, String tag, Editable output,
|
||||||
XMLReader reader) {
|
XMLReader reader) {
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case "ul":
|
case "ul":
|
||||||
if (opening) {
|
if (opening) {
|
||||||
@ -525,7 +525,7 @@ public final class Utils {
|
|||||||
String versionName = null;
|
String versionName = null;
|
||||||
try {
|
try {
|
||||||
versionName = context.getPackageManager()
|
versionName = context.getPackageManager()
|
||||||
.getPackageInfo(context.getPackageName(), 0).versionName;
|
.getPackageInfo(context.getPackageName(), 0).versionName;
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
Log.e(TAG, "Could not get client version name", e);
|
Log.e(TAG, "Could not get client version name", e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user