From 4a943184544159a57ca749af53bab0f1a98435a1 Mon Sep 17 00:00:00 2001 From: Jack Palevich Date: Wed, 28 Oct 2009 19:38:05 -0700 Subject: [PATCH] Avoid trying to throw multiple exceptions at once. The typical usage pattern for the get_char helper function is: bool thrown = false; n = get_char(env, s, 0, 1000, &thrown); n += get_char(env, s, 1, 100, &thrown); n += get_char(env, s, 2, 10, &thrown); n += get_char(env, s, 3, 1, &thrown); if (thrown) return false; As you can see, get_char is called multiple times before the thrown flag is checked. If the input text contains multiple incorrect characters, then we have to guard against throwing the same exception multiple times. (Because doing so will cause the Dalvik runtime to abort.) The fix is simple: modify get_char to check if an exception has already been thrown before throwing a new exception. --- core/jni/android_text_format_Time.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/jni/android_text_format_Time.cpp b/core/jni/android_text_format_Time.cpp index 98f4e035c0c95..fde6ca6e2b2a1 100644 --- a/core/jni/android_text_format_Time.cpp +++ b/core/jni/android_text_format_Time.cpp @@ -367,10 +367,12 @@ static int get_char(JNIEnv* env, const jchar *s, int spos, int mul, if (c >= '0' && c <= '9') { return (c - '0') * mul; } else { - char msg[100]; - sprintf(msg, "Parse error at pos=%d", spos); - jniThrowException(env, "android/util/TimeFormatException", msg); - *thrown = true; + if (!*thrown) { + char msg[100]; + sprintf(msg, "Parse error at pos=%d", spos); + jniThrowException(env, "android/util/TimeFormatException", msg); + *thrown = true; + } return 0; } }