aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Tang <gtang@affinegy.com>2017-05-16 15:42:52 -0500
committerGeorge Tang <gtang@affinegy.com>2017-06-02 14:36:14 +0000
commitcf917a206c05706b4ebfa1ecc96bae05663379c5 (patch)
treeb38cf61bdb5b3dc10836a4f6e86c6fd3d804e9af
parent2b25f758f3aa576970e4023f661dfead2da3c8f9 (diff)
ASACORE-3600 Android JUnit Test fails
toJavaString used NewStringUTF to transfer strings from c++ layer to java layer. When running tests on Android OS, JNI issues warning, "input is not valid Modified UTF-8: illegal [start, end, or continuation] byte". According to JNI documentation, it expects Modified UTF-8. The default character encoding of the Android platform is UTF-8, according to its Charset class. Thus, the code now uses the String constructor which will expect a byte array in the platform's default encoding. Change-Id: Ie4f17aef00209646ff55b22228f4cbfa995c477f Signed-off-by: George Tang <gtang@affinegy.com>
-rw-r--r--alljoyn_java/jni/CertificateX509.cc6
-rw-r--r--alljoyn_java/jni/alljoyn_java.cc2
-rw-r--r--alljoyn_java/jni/alljoyn_jni_helper.h2
3 files changed, 8 insertions, 2 deletions
diff --git a/alljoyn_java/jni/CertificateX509.cc b/alljoyn_java/jni/CertificateX509.cc
index b770e0d..aa61ce2 100644
--- a/alljoyn_java/jni/CertificateX509.cc
+++ b/alljoyn_java/jni/CertificateX509.cc
@@ -1569,8 +1569,12 @@ JNIEXPORT jstring JNICALL Java_org_alljoyn_bus_common_CertificateX509_toJavaStri
}
qcc::String certString = certPtr->ToString();
+ const unsigned char* cerStr = reinterpret_cast<const unsigned char*>(certString.c_str());
- return jenv->NewStringUTF(certString.c_str());
+ jmethodID strngCnstrctr = jenv->GetMethodID(CLS_String, "<init>", "([B)V");
+ jbyteArray strByteArray = ToJByteArray(cerStr, certString.length());
+
+ return (jstring) jenv->NewObject(CLS_String, strngCnstrctr, strByteArray);
}
/*
diff --git a/alljoyn_java/jni/alljoyn_java.cc b/alljoyn_java/jni/alljoyn_java.cc
index c9f7bb1..8f41182 100644
--- a/alljoyn_java/jni/alljoyn_java.cc
+++ b/alljoyn_java/jni/alljoyn_java.cc
@@ -767,7 +767,7 @@ static JavaVM* jvm = NULL;
/** java/lang cached items - these are guaranteed to be loaded at all times. */
static jclass CLS_Integer = NULL;
static jclass CLS_Object = NULL;
-static jclass CLS_String = NULL;
+jclass CLS_String = NULL;
/** org/alljoyn/bus */
jclass CLS_BusException = NULL;
diff --git a/alljoyn_java/jni/alljoyn_jni_helper.h b/alljoyn_java/jni/alljoyn_jni_helper.h
index 195202c..147ec40 100644
--- a/alljoyn_java/jni/alljoyn_jni_helper.h
+++ b/alljoyn_java/jni/alljoyn_jni_helper.h
@@ -34,6 +34,8 @@
#include <stdlib.h>
#include <alljoyn/MsgArg.h>
+extern jclass CLS_String;
+
extern jclass CLS_BusException;
extern jclass CLS_Status;