diff --git a/extensions/flac/src/main/jni/flac_jni.cc b/extensions/flac/src/main/jni/flac_jni.cc index c9e5d7ab36..59f37b0c2e 100644 --- a/extensions/flac/src/main/jni/flac_jni.cc +++ b/extensions/flac/src/main/jni/flac_jni.cc @@ -50,7 +50,8 @@ class JavaDataSource : public DataSource { ssize_t readAt(off64_t offset, void *const data, size_t size) { jobject byteBuffer = env->NewDirectByteBuffer(data, size); int result = env->CallIntMethod(flacDecoderJni, mid, byteBuffer); - if (env->ExceptionOccurred()) { + if (env->ExceptionCheck()) { + // Exception is thrown in Java when returning from the native call. result = -1; } env->DeleteLocalRef(byteBuffer); diff --git a/extensions/opus/src/main/jni/opus_jni.cc b/extensions/opus/src/main/jni/opus_jni.cc index 8d9c1a4152..9042e4cb89 100644 --- a/extensions/opus/src/main/jni/opus_jni.cc +++ b/extensions/opus/src/main/jni/opus_jni.cc @@ -103,8 +103,16 @@ DECODER_FUNC(jint, opusDecode, jlong jDecoder, jlong jTimeUs, kMaxOpusOutputPacketSizeSamples * kBytesPerSample * channelCount; env->CallObjectMethod(jOutputBuffer, outputBufferInit, jTimeUs, outputSize); + if (env->ExceptionCheck()) { + // Exception is thrown in Java when returning from the native call. + return -1; + } const jobject jOutputBufferData = env->CallObjectMethod(jOutputBuffer, outputBufferInit, jTimeUs, outputSize); + if (env->ExceptionCheck()) { + // Exception is thrown in Java when returning from the native call. + return -1; + } int16_t* outputBufferData = reinterpret_cast( env->GetDirectBufferAddress(jOutputBufferData)); diff --git a/extensions/vp9/src/main/jni/vpx_jni.cc b/extensions/vp9/src/main/jni/vpx_jni.cc index 1f36250e10..421b16d26d 100644 --- a/extensions/vp9/src/main/jni/vpx_jni.cc +++ b/extensions/vp9/src/main/jni/vpx_jni.cc @@ -362,7 +362,7 @@ DECODER_FUNC(jint, vpxGetFrame, jlong jContext, jobject jOutputBuffer) { // resize buffer if required. jboolean initResult = env->CallBooleanMethod(jOutputBuffer, initForRgbFrame, img->d_w, img->d_h); - if (initResult == JNI_FALSE) { + if (env->ExceptionCheck() || !initResult) { return -1; } @@ -400,7 +400,7 @@ DECODER_FUNC(jint, vpxGetFrame, jlong jContext, jobject jOutputBuffer) { jboolean initResult = env->CallBooleanMethod( jOutputBuffer, initForYuvFrame, img->d_w, img->d_h, img->stride[VPX_PLANE_Y], img->stride[VPX_PLANE_U], colorspace); - if (initResult == JNI_FALSE) { + if (env->ExceptionCheck() || !initResult) { return -1; }