JNI bug?
Marco Trudel
mtrudel@gmx.ch
Mon Jan 29 18:39:00 GMT 2007
Chris Gray wrote:
> On Monday 29 January 2007 19:15, Andrew Haley wrote:
>> Andrew Haley writes:
>> > Marco Trudel writes:
>>> > > [...]
>> > > private static native void nativePrintBoolean(boolean b);
>> > > private static native void nativePrintBooleanAsInt(boolean b);
>> > > }
>> > >
>> > > Now this 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);
>> > > }
>> > >
>> > > [...]
>>> Err, *why* are you doing this weird thing, anyway? Why not pass the
>> correct type?
>> Quite. javah or equivalent will generate a function prototype for
> nativeBooleanPrintAsInt() with 'jboolean b', not 'jint b'. Changing the type
> of a parameter and expecting the results to remain the same is, well,
> excessively optimistic.
Yes, the code definitely looks wrong. But I don't know if there should
be an automatic cast.
Anyway, it works with a Sun JRE, so we're stuck with the old discussion:
Do we want to add support for erroneous code just to be consistent with
a RE? There are good reasons for and good reasons against it...
Marco
More information about the Java
mailing list