Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4427110

JNI FromReflectedField function fails for static fields

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.3.1
    • 1.3.0
    • hotspot
    • rc1
    • generic
    • generic



        Name: ks84122 Date: 03/19/2001


        To reproduce: Call GetStaticObjectField on any class with a static field. Pass the resulting jobject to FromReflectedField and it will fail.

        There is no FromStaticReflectedField call in the JNI spec, so there is no workaround. Fix is to change FromReflectedField to support static fields.

        We had to patch this for 1.3.0 and must do so again for 1.3.1 .

        ###@###.### 2001-03-18

        FromReflectedField worked for static fields in 1.2. In hotspot, the VM crashes. To reproduce, please
        compile and run the following example:
        =============================================================================
         fromreffield.c
        ------------------
        import java.lang.reflect.*;

        public class fromreffield {

            public static void main (String[] args) {
                (new fromreffield()).dostuff();
            }
            
            public void dostuff() {
                Runtime.getRuntime().load("/home/sko/mytests/mynativelib1.so");
                a ins = new a();
                try {
                    final Field f = ins.getClass().getDeclaredField("s");
                    
                    System.out.println(fieldValue(ins, f));
                    
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            public static native String fieldValue(Object o, Field f);
        }

        class a {
            public a () {}
            
            static String s = "Hello Kirill";
        }

        mynativelib1.c
        ---------------------

        #include <stdio.h>
        #include "fromreffield.h"

        JNIEXPORT jstring JNICALL
        Java_fromreffield_fieldValue(JNIEnv *env, jclass cls1, jobject obj, jobject reffield)
        {

            jfieldID fid;
            jstring jstr;
            const char *str;
            jobject jobj;
            
            fid = (*env)->FromReflectedField(env, reffield);
            jstr = (*env)->GetStaticObjectField(env, obj, fid);
            
            str = (*env)->GetStringUTFChars(env, jstr, NULL);
            printf("c.s = \"%s\"\n", str);
            return jstr;
        }

        ===================================================

        Test run under 1.2:

        bash-2.00$ /usr/local/java/jdk1.2/solaris/bin/java fromreffield
        c.s = "Hello Kirill"
        Hello Kirill

        Test run under 1.3 hotspot:

        bash-2.00$ /export/tmp/java/jdk1.3/solaris/bin/java fromreffield
        #
        # HotSpot Virtual Machine Error, Unexpected Signal 10
        # Please report this error at
        # http://java.sun.com/cgi-bin/bugreport.cgi
        #
        # Error ID: 4F533F534F4C415249530E435050079A 01
        #
        # Problematic Thread: prio=5 tid=0x28148 nid=0x1 runnable
        #





        (Review ID: 118927)
        ======================================================================

              acorn Karen Kinnear (Inactive)
              ksoshals Kirill Soshalskiy (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: