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

GetObjectArrayElement() broken in j2sdk1.4.0

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.4.0
    • hotspot
    • x86
    • linux



      Name: rmT116609 Date: 03/14/2002


      FULL PRODUCT 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)

      FULL OPERATING SYSTEM VERSION :
      Red Hat Linux 7.2 , Redhat 7.1 on Intel

      DESCRIPTION OF THE PROBLEM :
      GetObjectArrayElement() broken in j2sdk1.4.0

      The test consists of sending the same object (ABC) as argument a and as the first element of an ObjectArray c.

      With Sun j2sdk1.4.0 (on RedHat Linux 7.2) we obtain:

      object a --> obj=-1073752740 cls=134730308 fid= 34
      object a --> texte='aaa'
      object c[0] --> obj=134730316 cls=134730320 fid= 0
      Failure2: fid(texte)=0
      Exception in thread "main" java.lang.NoSuchFieldError: texte

      We observe that the obj address, as returned by GetObjectArrayElement() is not the same in a and in c[0]. This is a bug.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      LD_LIBRARY_PATH=. ; export LD_LIBRARY_PATH
      /usr/java/j2sdk1.4.0/bin/javac BugJNI.java
      /usr/java/j2sdk1.4.0/bin/javah DEF gcc -c -fPIC *.c
      gcc -shared -o libBugJNI.so *.o
      /usr/java/j2sdk1.4.0/bin/java -Xcheck:jni ABCDemo

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      GetObjectArrayElement() broken in j2sdk1.4.0

      The test consists of sending the same object (ABC) as argument a and as the first element of an ObjectArray c.

      With Kaffe, we obtain:

      object a --> obj=136050432 cls=136032328 fid= 136050456
      object a --> texte='aaa'
      entering in native exec n=2
      object c[0] --> obj=136050432 cls=136032328 fid= 136050456
      object c[0] --> texte='aaa'
      object c[1] --> obj=136050840 cls=136032328 fid= 136050456
      object c[1] --> texte='bbb'

      We observe that the obj address, as returned by GetObjectArrayElement()
      is the same in a and in c[0]. This is OK.

      With Sun j2sdk1.4.0 (on RedHat Linux 7.2) we obtain:

      object a --> obj=-1073752740 cls=134730308 fid= 34
      object a --> texte='aaa'
      object c[0] --> obj=134730316 cls=134730320 fid= 0
      Failure2: fid(texte)=0
      Exception in thread "main" java.lang.NoSuchFieldError: texte

      We observe that the obj address, as returned by GetObjectArrayElement() is not the same in a and in c[0]. This is a bug.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Failure2: fid(texte)=0
      Exception in thread "main" java.lang.NoSuchFieldError: texte

      This bug can be reproduced always.

      ---------- BEGIN SOURCE -----------------------------------------------
      == file BugJNI.java ==

      class ABC {
        String texte;
      }
      class ABCDemo {
        public static void main(String args[]) {
          ABC a = new ABC();
          ABC b = new ABC();
          a.texte = "aaa";
          b.texte = "bbb";
          ABC[] c = {a, b};
          DEF my_def = new DEF();
          my_def.exec(a, c);
        }
      }
      class DEF {
        static {
          System.loadLibrary("BugJNI");
        }
        public native void exec(ABC a, ABC[] c);

      == file BugJNI.c ==

      #include <jni.h>
      #include <stdio.h>
      #include "DEF.h"

      JNIEXPORT void JNICALL Java_DEF_exec(JNIEnv *env, jobject this, jobject a, jobjectArray c) {
         jclass cls = (*env)->GetObjectClass(env, a);
         long i;
         jfieldID fid;
         const char *str;
         jint n;
         jstring jstr;
         
         /* recover the text in object a */
         fid = (*env)->GetFieldID(env, cls, "texte", "Ljava/lang/String;");
         printf("object a --> obj=%d cls=%d fid= %d\n",a,cls,fid);
         if (fid == 0) {
           printf("Failure1: fid(texte)=0\n");
           return;
         }
         jstr = (*env)->GetObjectField(env, a, fid);
         str = (*env)->GetStringUTFChars(env, jstr, 0);
         printf("object a --> texte='%s'\n",str);
         (*env)->ReleaseStringUTFChars(env, jstr, str);
         
         /* recover the text in object c[i] */
         n = (*env)->GetArrayLength(env, c);
         for (i = 0; i < n; ++i) {
           jobject obj = (*env)->GetObjectArrayElement(env, c, i);
           jclass cls = (*env)->GetObjectClass(env, obj);
           fid = (*env)->GetFieldID(env, cls, "texte", "Ljava.lang.String;");
           printf("object c[%d] --> obj=%d cls=%d fid= %d\n",i,obj,cls,fid);
           if (fid == 0) {
             printf("Failure2: fid(texte)=0\n");
             return;
           }
           jstr = (*env)->GetObjectField(env, obj, fid);
           str = (*env)->GetStringUTFChars(env, jstr, 0);
           printf("object c[%d] --> texte='%s'\n",i,str);
           (*env)->ReleaseStringUTFChars(env, jstr, str);
         }
      }

      }

      ---------- END SOURCE ----------

      (Review ID: 144135)
      ======================================================================

            hhuangsunw Hui Huang (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: