1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** JNI utils for nativehelper-internal use. */ 18 19 #pragma once 20 21 #include <jni.h> 22 23 #if defined(__cplusplus) 24 25 #if !defined(DISALLOW_COPY_AND_ASSIGN) 26 // DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. It goes in the private: 27 // declarations in a class. 28 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 29 TypeName(const TypeName&) = delete; \ 30 void operator=(const TypeName&) = delete 31 #endif // !defined(DISALLOW_COPY_AND_ASSIGN) 32 33 // This seems a header-only include. Provide NPE throwing. jniThrowNullPointerException(JNIEnv * env)34static inline int jniThrowNullPointerException(JNIEnv* env) { 35 if (env->ExceptionCheck()) { 36 // Drop any pending exception. 37 env->ExceptionClear(); 38 } 39 40 jclass e_class = env->FindClass("java/lang/NullPointerException"); 41 if (e_class == nullptr) { 42 return -1; 43 } 44 45 if (env->ThrowNew(e_class, nullptr) != JNI_OK) { 46 env->DeleteLocalRef(e_class); 47 return -1; 48 } 49 50 env->DeleteLocalRef(e_class); 51 return 0; 52 } 53 54 #endif // defined(__cplusplus) 55 56