Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[WEEX-169] [android] Fix new String null pointer crash when byte arr…
Browse files Browse the repository at this point in the history
…ay is null

close #938
  • Loading branch information
yuhun-alibaba authored and acton393 committed Dec 29, 2017
1 parent ec3db13 commit 11a1f3e
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,15 @@ public int initFrameworkEnv(String framework, WXParams params, String cacheDir,
*/

public int callNative(String instanceId, byte [] tasks, String callback) {
try {
return callNative(instanceId,new String(tasks),callback);
} catch (Throwable e) {
//catch everything during call native.
// if(WXEnvironment.isApkDebugable()){
WXLogUtils.e(TAG,"callNative throw exception:"+e.getMessage());
// }
return 0;
}
}

public int callNative(String instanceId, String tasks, String callback) {
Expand Down Expand Up @@ -137,7 +145,12 @@ public int callNative(String instanceId, String tasks, String callback) {
return errorCode;
}
public int callAddElement(String instanceId, String ref,byte[] dom,String index, String callback) {
return callAddElement(instanceId,ref, new String(dom),index,callback);
try {
return callAddElement(instanceId,ref,new String(dom),index,callback);
} catch (Throwable e) {
WXLogUtils.e(TAG,"callAddElement throw exception:"+e.getMessage());
return 0;
}
}

/**
Expand All @@ -149,7 +162,12 @@ public int callAddElement(String instanceId, String ref,byte[] dom,String index,
*/

public int callCreateBody(String instanceId, byte [] tasks, String callback) {
return callCreateBody(instanceId,new String(tasks),callback);
try {
return callCreateBody(instanceId, new String(tasks),callback);
} catch (Throwable e) {
WXLogUtils.e(TAG,"callCreateBody throw exception:"+e.getMessage());
return 0;
}
}

public int callCreateBody(String instanceId, String tasks, String callback) {
Expand Down Expand Up @@ -231,10 +249,10 @@ public void reportJSException(String instanceId, String func, String exception)
@Override
public Object callNativeModule(String instanceId, String module, String method, byte [] arguments, byte [] options) {

JSONArray argArray = JSON.parseArray(new String(arguments));
JSONArray argArray = JSON.parseArray(arguments == null ? new String("") : new String(arguments));
JSONObject optionsObj = null;
if (options != null) {
optionsObj = JSON.parseObject(new String(options));
optionsObj = JSON.parseObject(options == null ? new String("") :new String(options));
}
Object object = WXBridgeManager.getInstance().callNativeModule(instanceId,module,method,argArray,optionsObj);
return new WXJSObject(object);
Expand All @@ -250,7 +268,7 @@ public Object callNativeModule(String instanceId, String module, String method,
*/
@Override
public void callNativeComponent(String instanceId, String componentRef, String method, byte [] arguments, byte [] options) {
JSONArray argArray = JSON.parseArray(new String(arguments));
JSONArray argArray = JSON.parseArray(arguments == null ? new String("") : new String(arguments));
WXBridgeManager.getInstance().callNativeComponent(instanceId,componentRef,method,argArray,options);
}

Expand Down Expand Up @@ -369,7 +387,7 @@ public int callUpdateAttrs(String instanceId, String ref, byte [] tasks, String
}
int errorCode = IWXBridge.INSTANCE_RENDERING;
try {
errorCode = WXBridgeManager.getInstance().callUpdateAttrs(instanceId, ref, new String(tasks), callback);
errorCode = WXBridgeManager.getInstance().callUpdateAttrs(instanceId, ref, tasks == null ? new String("") : new String(tasks), callback);
} catch (Throwable e) {
//catch everything during call native.
if(WXEnvironment.isApkDebugable()){
Expand Down

0 comments on commit 11a1f3e

Please sign in to comment.