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:
Hans-Christoph Steiner 2016-06-28 00:11:25 +02:00 committed by Danial Behzadi
parent d174ea8d3e
commit fe7e299df9

View File

@ -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) {
FileInputStream fis = null;
try {
@ -387,13 +392,8 @@ public final class Utils {
byte[] mdbytes = md.digest();
return toHexString(mdbytes).toLowerCase(Locale.ENGLISH);
} catch (IOException e) {
Log.e(TAG, "Error reading \"" + apk.getAbsolutePath()
+ "\" to compute " + algo + " hash.", e);
return null;
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "Device does not support " + algo + " MessageDisgest algorithm");
return null;
} catch (IOException | NoSuchAlgorithmException e) {
throw new IllegalArgumentException(e);
} finally {
closeQuietly(fis);
}