Skip to content

Commit b6a5bea

Browse files
Fix null pointer exception (#2761)
* Fix npe for copyNecessaryFilesFromCurrentPackage * Reformat code
1 parent 94bcd15 commit b6a5bea

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import java.security.interfaces.*;
1111

12-
1312
import org.json.JSONArray;
1413
import org.json.JSONException;
1514
import org.json.JSONObject;
@@ -86,8 +85,12 @@ private static String computeHash(InputStream dataStream) {
8685
throw new CodePushUnknownException("Unable to compute hash of update contents.", e);
8786
} finally {
8887
try {
89-
if (digestInputStream != null) digestInputStream.close();
90-
if (dataStream != null) dataStream.close();
88+
if (digestInputStream != null) {
89+
digestInputStream.close();
90+
}
91+
if (dataStream != null) {
92+
dataStream.close();
93+
}
9194
} catch (IOException e) {
9295
e.printStackTrace();
9396
}
@@ -98,7 +101,11 @@ private static String computeHash(InputStream dataStream) {
98101
}
99102

100103
public static void copyNecessaryFilesFromCurrentPackage(String diffManifestFilePath, String currentPackageFolderPath, String newPackageFolderPath) throws IOException {
101-
FileUtils.copyDirectoryContents(currentPackageFolderPath, newPackageFolderPath);
104+
if (currentPackageFolderPath == null || !new File(currentPackageFolderPath).exists()) {
105+
CodePushUtils.log("Unable to copy files from current package during diff update, because currentPackageFolderPath is invalid.");
106+
return;
107+
}
108+
FileUtils.copyDirectoryContents(currentPackageFolderPath, newPackageFolderPath);
102109
JSONObject diffManifest = CodePushUtils.getJsonObjectFromFile(diffManifestFilePath);
103110
try {
104111
JSONArray deletedFiles = diffManifest.getJSONArray("deletedFiles");
@@ -184,7 +191,7 @@ public static void verifyFolderHash(String folderPath, String expectedHash) {
184191
public static Map<String, Object> verifyAndDecodeJWT(String jwt, PublicKey publicKey) {
185192
try {
186193
SignedJWT signedJWT = SignedJWT.parse(jwt);
187-
JWSVerifier verifier = new RSASSAVerifier((RSAPublicKey)publicKey);
194+
JWSVerifier verifier = new RSASSAVerifier((RSAPublicKey) publicKey);
188195
if (signedJWT.verify(verifier)) {
189196
Map<String, Object> claims = signedJWT.getJWTClaimsSet().getClaims();
190197
CodePushUtils.log("JWT verification succeeded, payload content: " + claims.toString());
@@ -217,7 +224,7 @@ public static PublicKey parsePublicKey(String stringPublicKey) {
217224
}
218225
}
219226

220-
public static String getSignatureFilePath(String updateFolderPath){
227+
public static String getSignatureFilePath(String updateFolderPath) {
221228
return CodePushUtils.appendPathComponent(
222229
CodePushUtils.appendPathComponent(updateFolderPath, CodePushConstants.CODE_PUSH_FOLDER_PREFIX),
223230
CodePushConstants.BUNDLE_JWT_FILE
@@ -254,7 +261,7 @@ public static void verifyUpdateSignature(String folderPath, String packageHash,
254261
throw new CodePushInvalidUpdateException("The update could not be verified because it was not signed by a trusted party.");
255262
}
256263

257-
final String contentHash = (String)claims.get("contentHash");
264+
final String contentHash = (String) claims.get("contentHash");
258265
if (contentHash == null) {
259266
throw new CodePushInvalidUpdateException("The update could not be verified because the signature did not specify a content hash.");
260267
}
@@ -265,4 +272,4 @@ public static void verifyUpdateSignature(String folderPath, String packageHash,
265272

266273
CodePushUtils.log("The update contents succeeded the code signing check.");
267274
}
268-
}
275+
}

0 commit comments

Comments
 (0)