Use jniThrowException for exception throwing from native code.
I'll do media and the generated gl stuff separately. Otherwise, this
cleans up all direct calls of ThrowNew/Throw except the one in the
binder that needs to remain.
Change-Id: I8f95a5f020f53b25926ad31ac0c9477ddf85d04b
diff --git a/core/jni/android_util_XmlBlock.cpp b/core/jni/android_util_XmlBlock.cpp
index 8887fdc..45728db 100644
--- a/core/jni/android_util_XmlBlock.cpp
+++ b/core/jni/android_util_XmlBlock.cpp
@@ -2,22 +2,23 @@
**
** Copyright 2006, The Android Open Source Project
**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
**
-** http://www.apache.org/licenses/LICENSE-2.0
+** http://www.apache.org/licenses/LICENSE-2.0
**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
** limitations under the License.
*/
#define LOG_TAG "XmlBlock"
#include "jni.h"
+#include "JNIHelp.h"
#include <utils/misc.h>
#include <android_runtime/AndroidRuntime.h>
#include <utils/AssetManager.h>
@@ -31,28 +32,18 @@
// ----------------------------------------------------------------------------
-static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL)
-{
- jclass npeClazz;
-
- npeClazz = env->FindClass(exc);
- LOG_FATAL_IF(npeClazz == NULL, "Unable to find class %s", exc);
-
- env->ThrowNew(npeClazz, msg);
-}
-
static jint android_content_XmlBlock_nativeCreate(JNIEnv* env, jobject clazz,
jbyteArray bArray,
jint off, jint len)
{
if (bArray == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
jsize bLen = env->GetArrayLength(bArray);
if (off < 0 || off >= bLen || len < 0 || len > bLen || (off+len) > bLen) {
- doThrow(env, "java/lang/IndexOutOfBoundsException");
+ jniThrowException(env, "java/lang/IndexOutOfBoundsException", NULL);
return 0;
}
@@ -61,7 +52,7 @@
env->ReleaseByteArrayElements(bArray, b, 0);
if (osb == NULL || osb->getError() != NO_ERROR) {
- doThrow(env, "java/lang/IllegalArgumentException");
+ jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
return 0;
}
@@ -73,7 +64,7 @@
{
ResXMLTree* osb = (ResXMLTree*)token;
if (osb == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
@@ -85,13 +76,13 @@
{
ResXMLTree* osb = (ResXMLTree*)token;
if (osb == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
ResXMLParser* st = new ResXMLParser(*osb);
if (st == NULL) {
- doThrow(env, "java/lang/OutOfMemoryError");
+ jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
return 0;
}
@@ -125,9 +116,9 @@
goto bad;
}
} while (true);
-
+
bad:
- doThrow(env, "org/xmlpull/v1/XmlPullParserException",
+ jniThrowException(env, "org/xmlpull/v1/XmlPullParserException",
"Corrupt XML binary file");
return ResXMLParser::BAD_DOCUMENT;
}
@@ -139,7 +130,7 @@
if (st == NULL) {
return -1;
}
-
+
return (jint)st->getElementNamespaceID();
}
@@ -170,7 +161,7 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
@@ -182,7 +173,7 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
@@ -194,10 +185,10 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
-
+
return (jint)st->getAttributeNamespaceID(idx);
}
@@ -206,7 +197,7 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
@@ -218,7 +209,7 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
@@ -230,7 +221,7 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
@@ -242,7 +233,7 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
@@ -254,7 +245,7 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
@@ -267,7 +258,7 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL || name == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
@@ -277,7 +268,7 @@
ns16 = env->GetStringChars(ns, NULL);
nsLen = env->GetStringLength(ns);
}
-
+
const char16_t* name16 = env->GetStringChars(name, NULL);
jsize nameLen = env->GetStringLength(name);
@@ -296,7 +287,7 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
@@ -309,10 +300,10 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
-
+
ssize_t idx = st->indexOfClass();
return idx >= 0 ? (jint)st->getAttributeValueStringID(idx) : -1;
}
@@ -322,7 +313,7 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return 0;
}
@@ -336,7 +327,7 @@
return 0;
}
- return value.dataType == value.TYPE_REFERENCE
+ return value.dataType == value.TYPE_REFERENCE
|| value.dataType == value.TYPE_ATTRIBUTE
? value.data : 0;
}
@@ -346,7 +337,7 @@
{
ResXMLParser* st = (ResXMLParser*)token;
if (st == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return;
}
@@ -358,7 +349,7 @@
{
ResXMLTree* osb = (ResXMLTree*)token;
if (osb == NULL) {
- doThrow(env, "java/lang/NullPointerException");
+ jniThrowNullPointerException(env, NULL);
return;
}
@@ -423,4 +414,3 @@
}
}; // namespace android
-