JDK-4860727 : -Xcheck:jni aborts JVM incorrectly with "Field type (static) mismatch..."
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.4.0,1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,linux,solaris_7,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 2003-05-08
  • Updated: 2013-06-21
  • Resolved: 2003-05-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 b24Fixed
Related Reports
Duplicate :  
Duplicate :  
Description

Name: rmT116609			Date: 05/08/2003


FULL PRODUCT VERSION :
Occurs in 1.4.0 and 1.4.2Beta (and presumably 1.4.1)

j2sdk1.4.0/bin/java -version
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

j2sdk1.4.2B/bin/java -version
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)


FULL OS VERSION :
Windows NT ( Windows NT Version 4.0 )
Linux x86 (Linux rh71mp-pod 2.4.2-2smp #1 SMP Sun Apr 8 20:21:34 EDT 2001 i686 unknown)
Solaris sparc (SunOS lorax 5.8 Generic_108528-01 sun4u sparc SUNW,Ultra-80)

A DESCRIPTION OF THE PROBLEM :
When running the JVM Invocation interface started with option -Xcheck:jni, a call to the JNI method GetStaticFieldID() on a static boolean array causes the the JVM to abort with the error:

FATAL ERROR in native method: Field type (static) mismatch in JNI get/set field operations

Notes:
1. a call to a static boolean works fine.
2. if Xcheck:jni is not specified, the call works without error, setting the value properly.
3. The test case is Windows only, but a similar test case has the same result on Linux and Solaris







STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Build test code below.




EXPECTED VERSUS ACTUAL BEHAVIOR :
The JVM should not abort as the field being queried is a static member:

JVM start success
staticProp clazz=XXXXXXXX
staticProp::arr_b fieldID=XXXXXXXX
success calling SetStaticObjectField

JVM start success
staticProp clazz=XXXXXXXX
staticProp::arr_b fieldID=XXXXXXXX
FATAL ERROR in native method: Field type (static) mismatch in JNI get/set field operations


ERROR MESSAGES/STACK TRACES THAT OCCUR :
FATAL ERROR in native method: Field type (static) mismatch in JNI get/set field operations

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
------------------
staticProp.java
------------------
public class staticProp {
 public static boolean b=false;
 public static boolean[] arr_b=null;
}

------------------
bStaticField.c
------------------
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

// Note: This needs changed to point to the location of jvm.dll/libjvm.so
#define JAVA14_JVMDLL "E:\\j2sdk1.4.0\\jre\\bin\\client\\jvm.dll"

// Function pointer
typedef jint (JNICALL *CreateJavaVM_t) (JavaVM**, void**, void*);


// Dynamically load the JVM
//
void *JNU_FindCreateJavaVM(const char *vmLibPath)
{
   HINSTANCE hJVMLib = LoadLibrary(vmLibPath);
   if (hJVMLib == NULL) {
     return NULL;
   }
   return GetProcAddress(hJVMLib, "JNI_CreateJavaVM");
}


int main()
{
    CreateJavaVM_t pCreateJVM;
    JNIEnv* env = (JNIEnv*)0;
    JavaVM* jvm = (JavaVM*)0;
    JavaVMInitArgs vm_args;

    const char* sJVMLoc = JAVA14_JVMDLL;

    jclass clazz;
    jfieldID fID;

    jint status = JNI_OK;
    JavaVMOption   options[12];
    int nOpts = 0;

    vm_args.version = JNI_VERSION_1_2;
    options[nOpts].extraInfo = NULL;
    options[nOpts++].optionString = "-Xcheck:jni";
    vm_args.nOptions = nOpts;
    vm_args.options = options;

    pCreateJVM = JNU_FindCreateJavaVM(sJVMLoc);

    vm_args.ignoreUnrecognized = JNI_TRUE;
    status = (*pCreateJVM)(&jvm, (void**)(&env), (void*)(&vm_args));
    if (0 != status) {
        printf( "(ERR starting JVM status=%p\n", status);
        return EXIT_FAILURE;
    }

printf( "JVM start success\n");

    clazz = (*env)->FindClass(env, "staticProp");
    printf( "staticProp clazz=%p\n", clazz);

#if 0
    // static member 'b' works fine
    fID = (*env)->GetStaticFieldID(env, clazz, "b", "Z");
    printf( "staticProp::b fieldID=%p\n", fID);
    (*env)->SetStaticBooleanField(env, clazz, fID, JNI_TRUE);
#endif

    // This call exits the JVM with a FATAL error when -Xcheck:jni is turned on
    fID = (*env)->GetStaticFieldID(env, clazz, "arr_b", "[Z");
    printf( "staticProp::arr_b fieldID=%p\n", fID);
    (*env)->SetStaticObjectField(env, clazz, fID, 0);
    printf( "success calling SetStaticObjectField\n");

    return EXIT_SUCCESS;
}

------------------
Building and running the test case
------------------
1. Change JAVA14_JVMDLL macro in bStaticField.c to point to your JVM.dll
2. javac -classpath . staticProp.java
3. cl -c -I<SDK14>\include -I<SDK14>\include\win32 bStaticField.c
4. link -out:bStaticField.exe bStaticField.obj
5. Run bStaticField
---------- END SOURCE ----------
(Review ID: 184822) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis-rc tiger FIXED IN: mantis-rc INTEGRATED IN: mantis-b24 mantis-rc tiger-b08
14-06-2004

SUGGESTED FIX ###@###.### 2003-05-13 *** c:/tmp/geta1628 Tue May 13 13:54:04 2003 --- jniCheck.cpp Tue May 13 13:54:02 2003 *************** *** 176,182 **** if (!instanceKlass::cast(f_oop)->jni_find_local_field_from_offset( id->offset(), true, &fd)) ReportJNIFatalError(thr, fatal_static_field_not_found); ! if (fd.field_type() != ftype) ReportJNIFatalError(thr, fatal_static_field_mismatch); } --- 176,183 ---- if (!instanceKlass::cast(f_oop)->jni_find_local_field_from_offset( id->offset(), true, &fd)) ReportJNIFatalError(thr, fatal_static_field_not_found); ! if ((fd.field_type() != ftype) && ! !(fd.field_type() == T_ARRAY && ftype == T_OBJECT)) { ReportJNIFatalError(thr, fatal_static_field_mismatch); }
11-06-2004

EVALUATION ###@###.### 2003-05-13 This is a real bug. There is a test made in checkInstanceFieldID which needs to be copied into checkStaticFieldID.
13-05-2003