Bug 30673 - [jni] Different behaviour than a Sun JRE
Summary: [jni] Different behaviour than a Sun JRE
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.3.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-01 21:32 UTC by Marco Trudel
Modified: 2007-02-01 21:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Trudel 2007-02-01 21:32:37 UTC
A JNI problem where GCJ isn't doing the same as a Sun JDK:

public class NativeBooleanTest
{
    public static void main(String[] args)
    {
        System.loadLibrary("nativeBoolean");
        nativePrintBoolean(false);
        nativePrintBoolean(true);
        nativePrintBooleanAsInt(false);
        nativePrintBooleanAsInt(true);
    }
    
    private static native void nativePrintBoolean(boolean b);
    private static native void nativePrintBooleanAsInt(boolean b);
}

C code:

#include <jni.h>

JNIEXPORT void JNICALL Java_NativeBooleanTest_nativePrintBoolean
    (JNIEnv *env, jclass c, jboolean b)
{
    printf("nativePrintBoolean: %d\n", b);
}

JNIEXPORT void JNICALL Java_NativeBooleanTest_nativePrintBooleanAsInt
    (JNIEnv *env, jclass c, jint b)
{
    printf("nativePrintBooleanAsInt: %d\n", b);
}


On a sun JVM, the output will be:
nativePrintBoolean: 0
nativePrintBoolean: 1
nativePrintBooleanAsInt: 0
nativePrintBooleanAsInt: 1

GCJ will print something like:
nativePrintBoolean: 0
nativePrintBoolean: 1
nativePrintBooleanAsInt: 10084864 
nativePrintBooleanAsInt: 10084865