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

GetStaticFieldID cannot access a field inherited from an interface

XMLWordPrintable

    • 1.1fcs
    • sparc
    • solaris_2.5
    • Not verified



      Name: laC46010 Date: 01/23/97


      The test below shows that GetStaticFieldID cannot access "itrf_fld" field
      of the class gsfi00101 which is inherited from the interface "Interf".

      To run the test, set environment variables JH (Java home) and CC (C compiler)
      and run "jnirun" script.

      ./jnirun
      GetStaticFieldID: cannot get interface field
      Exception caught: java.lang.NoSuchFieldError: itrf_fld

      ::::::::::::::
      jnirun
      ::::::::::::::
      #!/usr/bin/csh

      #setenv JH /export/ld32/dest/jdk1.1beta3/solaris
      #setenv CC /export/ld4/set/dist/sparc-S2/SC4.2/bin/cc

      $JH/bin/javac -d . *[1-9].java
      $CC -KPIC -G -I$JH/include -I$JH/include/solaris -o libtest.so gsfi00101.c
      setenv LD_LIBRARY_PATH ".:$LD_LIBRARY_PATH"
      setenv CLASSPATH .
      $JH/bin/java javasoft.sqe.tests.vm.gsfi001.gsfi00101.gsfi00101

      ::::::::::::::
      gsfi00101.c
      ::::::::::::::
      #include <stdio.h>
      #include "native.h"

      #ifdef __cplusplus
      extern "C"
      #endif

      #ifdef __cplusplus
      #define JNI_ENV_ARG(x,y) y
      #define JNI_ENV_PTR(x) x
      #else
      #define JNI_ENV_ARG(x,y) x,y
      #define JNI_ENV_PTR(x) (*x)
      #endif

      void Java_javasoft_sqe_tests_vm_gsfi001_gsfi00101_gsfi00101_f
      (JNIEnv *env,jobject obj)
       {
      jclass jc;
      jfieldID jfi;

      jc = JNI_ENV_PTR(env) -> GetObjectClass(JNI_ENV_ARG(env,obj));
      jfi = JNI_ENV_PTR(env) -> GetStaticFieldID(JNI_ENV_ARG(env,jc),"itrf_fld","I");
      if (jfi == NULL)
      printf("GetStaticFieldID: cannot get interface field\n");
       }

      ::::::::::::::
      gsfi00101.java
      ::::::::::::::
      package javasoft.sqe.tests.vm.gsfi001.gsfi00101;
      import java.io.PrintStream;

      interface Interf {
        int itrf_fld = 1;
        void fict();
      }

      public class gsfi00101 implements Interf {

        public void fict() { System.out.println("fict method"); }

        public static void main(String argv[]) {
          gsfi00101 tob = new gsfi00101();
          try {
            tob.f();
          } catch (Throwable e) {
            System.out.println("Exception caught: "+e);
          }
        }

        public native void f();

        static {
          System.loadLibrary("test");
        }
      }
      ======================================================================

            sliangsunw Sheng Liang (Inactive)
            leosunw Leo Leo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: