blob: 9cb81953cb882d2ceac615619c1cae06d2429ecf [file] [log] [blame]
Fairphone ODM25c12f52023-12-15 17:24:06 +08001/*
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#pragma once
18
19#include <jni.h>
20
21#if defined(__cplusplus)
22
23#if !defined(DISALLOW_COPY_AND_ASSIGN)
24// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. It goes in the private:
25// declarations in a class.
26#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
27 TypeName(const TypeName&) = delete; \
28 void operator=(const TypeName&) = delete
29#endif // !defined(DISALLOW_COPY_AND_ASSIGN)
30
31// This seems a header-only include. Provide NPE throwing.
32static inline int jniThrowNullPointerException(JNIEnv* env) {
33 if (env->ExceptionCheck()) {
34 // Drop any pending exception.
35 env->ExceptionClear();
36 }
37
38 jclass e_class = env->FindClass("java/lang/NullPointerException");
39 if (e_class == nullptr) {
40 return -1;
41 }
42
43 if (env->ThrowNew(e_class, nullptr) != JNI_OK) {
44 env->DeleteLocalRef(e_class);
45 return -1;
46 }
47
48 env->DeleteLocalRef(e_class);
49 return 0;
50}
51
52#endif // defined(__cplusplus)
53