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 8919199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:57:31+00:00 2026-06-15T05:57:31+00:00

This might sound weird but I am struggling with this bug for past 2

  • 0

This might sound weird but I am struggling with this bug for past 2 days.

  1. I have a boolean array in java that is initialised using a Random boolean generator.

  2. After that the boolean array is acted upon by a function in C (called using JNI) and the modified boolean array is returned to java. When I hand over the boolean array to C, it is converted to unsigned char and converted back to jbooleanArray before being handed back to java.

  3. Now I run the following code (there is a for loop over i):

    if(chosen_packet[i] == false)
    {
         pkt.first[i] = 0;
         System.out.print(chosen_packet[i]);
    }
    if(chosen_packet[i] == true)
    {
         pkt.first[i] = 1;
         System.out.print(chosen_packet[i]);
    }
    

The problem is that sometimes when chosen_packet[i] is true it still does not enter the second if condition. This happens sometimes and sometimes the code works just fine. When I print chosen_packet[i] in such a case it is printed as true yet it does not enter the second if condition. What could be the possible reason for this seeming corruption of the boolean array ?

EDIT: This is how I convert the boolean array to unsigned char in C:

 jboolean *element = (*env)->GetBooleanArrayElements(env,chosen_packet,0);
 for(j = 0; j < sz; j++)
          src_pkt[j] = (unsigned char)element[j];

This src_pkt is acted upon and then I convert it back to jboolean .

EDIT2: This is how I convert the unsigned char array back to jboolean:

 jbooleanArray arr = (*env)->NewBooleanArray(env,sz);
 (*env)->SetBooleanArrayRegion(env,arr,0,sz,src_pkts);
 (*env)->DeleteLocalRef(env,arr);
  • 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-15T05:57:32+00:00Added an answer on June 15, 2026 at 5:57 am

    It’s normal that if the boolean is true it does not enter in the first if since you are checking for it to be false in its condition.

    Your code can be simplified to (you should use if/else instead of two if checking for the different conditions).

    if (chosen_packet[i]) {
        pkt.first[i] = 1;
    } else {
        pkt.first[i] = 0;
    }
    System.out.print(chosen_packet[i]);
    

    or even

    pkt.first[i] = chosen_packet[i] ? 1 : 0;
    System.out.print(chosen_packet[i]);
    

    Edit

    If your program does not enter the second if, it means that the the var chosen_packet[i] is not true, you could use a debugger to verify what is the real value.

    As stated by fredcrs, are you sure that chosen_packet[i] is of type boolean?

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

Sidebar

Related Questions

This might sound like a weird question but I have C# Winform that I
This might sound kind of weird, but I have a query that joins two
This might sound weird, but when I open a solution that I dont know,
This might sound odd, but my issue is that I have a text string
This might sound rudimentary but, I have created tables by running queries in Workbench
This might sound like a reaaaally dumb question but... why do browsers have a
this might sound weird, but I was thinking about modules proposal and wondered if
This might sound stupid but I am still not clear about the Java Stack
OK so this might sound a bit weird! The thing is that in a
This question might sound weird, but how do I make a job fail? I

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.