Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8694457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:47:39+00:00 2026-06-13T00:47:39+00:00

I have gotten this error when setting the -Xcheck:jni option, and calling my native

  • 0

I have gotten this error when setting the -Xcheck:jni option, and calling my native method.

The error is :
FATAL ERROR in native method: Bad global or local ref passed to JNI

I shall paste the native method (C code) here, hope that anybody who knows what is wrong with this piece of code, will enlighten me. Thank you.

    #include <stdio.h>  
    #include <stdlib.h>  
    #include <string.h>  
    #include "fns_data.h"  
    #include "fns_client.h"  
    #include "sockRW.h"  
    #include "/usr/local/include/jni.h"  
    #include "JNIiSearchLib.h"  
    #include "com_eds_wise_util_JNIiSearchLib.h"  

    JNIEXPORT jstring JNICALL  
    Java_com_eds_wise_util_JNIiSearchLib_jniFNSSearchClient (  
        JNIEnv *env, jobject obj, jstring jip_addr, jint jport_number,  
        jstring jfield, jstring jquery_str, jint jhitnum)  
    {  
        HitIds           *hit_list   = NULL;  
        hitListPktStruct *hitPkt     = NULL;  
        int               hit_number = 0;  
        int               i          = 0;  
        int               fnsErrno   = 0;  
        char             *result_str = NULL;  
        jstring          *rslt_str   = NULL;  
        const char       *cip_addr   = NULL;  
        const char       *cquery_str = NULL;  
        char              errbuf[1024];  

        cip_addr   = (*env)->GetStringUTFChars(env, jip_addr, 0);  
        if (cip_addr == NULL) {  
            return ((* env)->NewStringUTF (env, "Error: Cannot get IP address."));  
        }  

        cquery_str = (*env)->GetStringUTFChars(env, jquery_str, 0);  
        if (cquery_str == NULL) {  
            (*env)->ReleaseStringUTFChars (env, jip_addr, cip_addr);  
            (*env)->DeleteLocalRef(env, cip_addr);  
            return ((* env)->NewStringUTF (env, "Error: Cannot get query string."));  
        }  
        printf ("[Java_JNILib_jniFNSSearchClient] ipaddress[%s] portnumber[%d]"  
                " querystr[%s]\n\n", cip_addr, jport_number, cquery_str);  

        /* Search and get back the handler & total hits 
         */  
        hit_list = fns_search_client0 (cip_addr, jport_number,  
                                       "PN", cquery_str, &hit_number);  


        /* Display total hits 
         */  
        printf ("Total hits = %d\n", hit_number);  


        /* Enumerate every item in the result list and display them. 
         * The results are returned as a string to Java in the following manner: 
         * 
         * "[hitresult1|hitresult2|hitresult3|..|hitresultN]\0" 
         * 
         *     where hitresultN = 94-byte record 
         * 
         * [+string94+|+string94]+stringTerminator  
         */  
        printf ("malloc[%d]\n", (hit_number * 95) + 3);  

        result_str = malloc (((hit_number * 95)+3) * sizeof(char));  
        if (result_str == NULL) {  
            printf ("Out of memory, unable to malloc\n");  
            rslt_str = (* env)->NewStringUTF (env, "Error: Out of memory, unable to malloc");  

            if (hit_list) {  
                FREE_STRING (hit_list);  
            }  
            if (hitPkt) {  
                FREE_HITLIST_STRUCT (hitPkt);  
            }  
            (*env)->ReleaseStringUTFChars (env, jip_addr, cip_addr);  
            (*env)->ReleaseStringUTFChars (env, jquery_str, cquery_str);  
            (*env)->DeleteLocalRef(env, cip_addr);  
            (*env)->DeleteLocalRef(env, cquery_str);  

            fflush(stdout);  
            return (rslt_str);  
        }  

        sprintf (result_str, "[");  
        for (i = 0; i < hit_number; i++) {  
            strcat (result_str, hitPkt->docNameList[i]);  
            if (i != (hit_number - 1)) {  
                strcat (result_str, "|");  
            }  
        }  
        strcat (result_str, "]");  

        printf ("\n\nFNS search result:[From Library]\n");  
        printf ("%s\n\n",result_str);  

        /* free the handler 
         */  
        if (hit_list) {  
            FREE_STRING (hit_list);  
        }  

        /* free the result lists 
         */  
        if (hitPkt) {  
            FREE_HITLIST_STRUCT (hitPkt);  
        }  

        /* prepare stuff for Java 
         */  
        rslt_str = (* env)->NewStringUTF (env, result_str);  

        /* free our memory 
         */  
        if (result_str) {  
            free (result_str);  
        }  
        (*env)->ReleaseStringUTFChars (env, jip_addr, cip_addr);  
        (*env)->ReleaseStringUTFChars (env, jquery_str, cquery_str);  
        (*env)->DeleteLocalRef(env, cip_addr);  
        (*env)->DeleteLocalRef(env, cquery_str);  

        fflush(stdout);  
        return (rslt_str);  
    }  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:47:41+00:00Added an answer on June 13, 2026 at 12:47 am

    I wonder how this even compiles. jstring is a pointer type already, so yours

    jstring          *rslt_str   = NULL;
    

    is a pointer to pointer, and i wonder how the compiler can take it as retval for GetStringUTFChars and returning it from your native method altogether.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of System.DirectoryServices.ActiveDirectory.Domain objects gotten via this method. How do I
Within my project I have gotten this error: Error 1 The type or namespace
I have gotten this error in the strings.xml file: error: Error parsing XML: unbound
I have never gotten this error before so I am not sure what to
I'm sure this is very simple. I have gotten colorbox to work before, but
I have tried for three days now and gotten nowhere on this.... I absolutely
After a recent submission I have gotten the following error: Invalid Signature - the
I have received this error Element CUSTOMERID is undefined in CLIENT. D:\Inetpub\wwwsitecom\wwwroot\rders.cfm:296 on a
Has anyone ever gotten this error or know what it relates to? I got
I have a problem in MSVC++ 2008 where VS2008 is throwing this compile error:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.