Android 4.0 JNI character conversion getstringutfchars () function bug

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.