In our project, the core part is written using JNI,
Convert the Java string to the C string. The conversion of the string is as follows:
const char const *p_passwd = (*env)->GetStringUTFChars(env, j_passwd, NULL);
Previously in Android 2.x, everything was normal.
An exception occurred after the upgrade to 4.0.
Error exits.
Trace found problems: j_passwd in the program is sometimes null, resulting in.
I didn't handle j_passwd being null at the time.
Is this a bug in Android 4.0?
View my test again:
The test code is as follows:
//testLOGI("begin GetStrinUTFChars(NULL)...");const char const *p_char = (*env)->GetStringUTFChars(env, NULL, 0);LOGI("end GetStrinUTFChars(NULL)...");//endtest
Output log:
10-25 18:51:06.440: I/EbenTest16245): begin GetStrinUTFChars(NULL)...10-25 18:51:06.440: W/dalvikvm(16245): JNI WARNING: received null jstring10-25 18:51:06.440: W/dalvikvm(16245): in Lcn/hpc/test;.testString:(Ljava/lang/String;)I (GetStringUTFChars)10-25 18:51:06.440: I/dalvikvm(16245): "main" prio=5 tid=1 NATIVE10-25 18:51:06.440: I/dalvikvm(16245): | group="main" sCount=0 dsCount=0 obj=0x2b51f460 self=0x1d22b8010-25 18:51:06.440: I/dalvikvm(16245): | sysTid=16245 nice=0 sched=0/0 cgrp=default handle=71690378410-25 18:51:06.440: I/dalvikvm(16245): | schedstat=( 0 0 0 ) utm=3 stm=2 core=110-25 18:59:10.075: E/dalvikvm(16645): VM aborting10-25 18:59:10.075: A/libc(16645): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1)
Only the first line begin getstrinutfchars (null )...
Logs without tests: no end getstrinutfchars (null )...
The application exits directly.
Try catch cannot be captured in Java.
JNI verification is more rigorous. getstrinutfchars (null) will exit directly. It is not a good thing.
Note: Do not pass null into the getstringutfchars () Conversion Function.