aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-09-19 17:08:00 +0200
committerSven Gothel <[email protected]>2020-09-19 17:08:00 +0200
commit7b5862b9283f48d5878057a3506138e3fc863578 (patch)
tree371e62ce7f42a71e5744b9b40249d4120f1c1959 /java
parent4b50a5e57aef84bc82a1dde3c77163d79ba3f60f (diff)
POctets::malloc: throw new exception type OutOfMemoryError early on malloc failure, also throw IllegalArgumentException on size <= 0
- Add exception type 'direct_bt::OutOfMemoryError' and wire it in helper_base for C++/JNI interoperability. - std::malloc may not return nullptr on zero size, but a valid dummy pointer usable by free. Hence check for malloc(0) and throw IllegalArgumentException - also throw OutOfMemoryError on nullptr == malloc(size)
Diffstat (limited to 'java')
-rw-r--r--java/jni/helper_base.cxx8
-rw-r--r--java/jni/helper_base.hpp1
2 files changed, 8 insertions, 1 deletions
diff --git a/java/jni/helper_base.cxx b/java/jni/helper_base.cxx
index 518b28a5..344a722f 100644
--- a/java/jni/helper_base.cxx
+++ b/java/jni/helper_base.cxx
@@ -236,6 +236,10 @@ void raise_java_exception(JNIEnv *env, const std::bad_alloc &e, const char* file
print_native_caught_exception_fwd2java(e, file, line);
env->ThrowNew(env->FindClass("java/lang/OutOfMemoryError"), e.what());
}
+void raise_java_exception(JNIEnv *env, const direct_bt::OutOfMemoryError &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/OutOfMemoryError"), e.what());
+}
void raise_java_exception(JNIEnv *env, const direct_bt::BluetoothException &e, const char* file, int line) {
print_native_caught_exception_fwd2java(e, file, line);
env->ThrowNew(env->FindClass("org/tinyb/BluetoothException"), e.what());
@@ -252,7 +256,9 @@ void rethrow_and_raise_java_exception_impl(JNIEnv *env, const char* file, int li
try {
// std::rethrow_exception(e);
throw; // re-throw current exception
- } catch (const std::bad_alloc &e) { \
+ } catch (const std::bad_alloc &e) {
+ raise_java_exception(env, e, file, line);
+ } catch (const direct_bt::OutOfMemoryError &e) {
raise_java_exception(env, e, file, line);
} catch (const direct_bt::InternalError &e) {
raise_java_exception(env, e, file, line);
diff --git a/java/jni/helper_base.hpp b/java/jni/helper_base.hpp
index 45372406..164f6793 100644
--- a/java/jni/helper_base.hpp
+++ b/java/jni/helper_base.hpp
@@ -252,6 +252,7 @@ void raise_java_exception(JNIEnv *env, const direct_bt::IllegalStateException &e
void raise_java_exception(JNIEnv *env, const direct_bt::UnsupportedOperationException &e, const char* file, int line);
void raise_java_exception(JNIEnv *env, const direct_bt::IndexOutOfBoundsException &e, const char* file, int line);
void raise_java_exception(JNIEnv *env, const std::bad_alloc &e, const char* file, int line);
+void raise_java_exception(JNIEnv *env, const direct_bt::OutOfMemoryError &e, const char* file, int line);
void raise_java_exception(JNIEnv *env, const direct_bt::BluetoothException &e, const char* file, int line);
void raise_java_exception(JNIEnv *env, const tinyb::BluetoothException &e, const char* file, int line);