Convert handle == nullptr from SegFault to user-friendly error. (#3021)

* Convert SegFault to user-friendly error.

* Apply the change to DMatrix API as well
This commit is contained in:
Yun Ni
2018-06-28 23:30:26 -07:00
committed by Philip Hyunsu Cho
parent 8bec8d5e9a
commit 30d10ab035
3 changed files with 35 additions and 5 deletions

View File

@@ -556,11 +556,12 @@ JNIEXPORT jint JNICALL Java_ml_dmlc_xgboost4j_java_XGBoostJNI_XGBoosterPredict
bst_ulong len;
float *result;
int ret = XGBoosterPredict(handle, dmat, joption_mask, (unsigned int) jntree_limit, &len, (const float **) &result);
jsize jlen = (jsize) len;
jfloatArray jarray = jenv->NewFloatArray(jlen);
jenv->SetFloatArrayRegion(jarray, 0, jlen, (jfloat *) result);
jenv->SetObjectArrayElement(jout, 0, jarray);
if (len) {
jsize jlen = (jsize) len;
jfloatArray jarray = jenv->NewFloatArray(jlen);
jenv->SetFloatArrayRegion(jarray, 0, jlen, (jfloat *) result);
jenv->SetObjectArrayElement(jout, 0, jarray);
}
return ret;
}