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

JNI CallStatic<Type>Method don't validate class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 9
    • 9
    • hotspot
    • None

      Specification of CallStatic<Type>Method family says:
      "The method ID must be derived from clazz, not from one of its superclasses."

      But the functions allow to pass not only the superclass declaring the type, but any arbitrary type.

      Example:
      ============================
      public class CallStaticTest {
          private static native void nativeMethod();

          public static void m() {
              System.out.println("Static method m is called!");
          }

          public static void main(String[] args) throws NoSuchMethodException {
              System.loadLibrary("CallStaticTest");
              nativeMethod();
          }
      }
      ============================
      #include "jni.h"

      JNIEXPORT void JNICALL Java_CallStaticTest_nativeMethod
        (JNIEnv * env, jclass clazz, jobject method)
      {
          jmethodID methodID = (*env)->GetStaticMethodID(env, clazz, "m", "()V");
          jclass stringClass = (*env)->FindClass(env, "java/lang/String");
          (*env)->CallStaticVoidMethod(env, stringClass, methodID);
      }
      ============================
      $ javac CallStaticTest.java -d classes
      $ gcc -m64 -shared -o CallStaticTest.dll -I"$jdk\include" -I'$jdk\include\win32' CallStaticTest.c
      $ java -cp classes CallStaticTest
      Static method m is called!
      ============================

            hseigel Harold Seigel (Inactive)
            slukyanov Stanislav Lukyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: