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

Call<Type>MethodA breaks argument values of short types

XMLWordPrintable

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



      Name: laC46010 Date: 01/23/97


      The test below shows that CallBooleanMethodA incorrectly passes
      argument values of types short, byte, char and float.

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

      > jnirun
      wrong short argument value:-251727040, should be -3842
      wrong byte argument value:-1711279272, should be -103
      wrong char argument value:, should be ?
      wrong float argument value:5.2336777E+13, should be 99.9

      ::::::::::::::
      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 . *.java
      $CC -KPIC -G -I$JH/include -I$JH/include/solaris -o libtest.so *.c
      setenv LD_LIBRARY_PATH ".:$LD_LIBRARY_PATH"
      setenv CLASSPATH .
      $JH/bin/java javasoft.sqe.tests.vm.czma001.czma00101.czma00101

      ::::::::::::::
      czma00101.java
      ::::::::::::::
      // Ident: %Z%%M% %I% %E%
      // Copyright %G% Sun Microsystems, Inc. All Rights Reserved

      package javasoft.sqe.tests.vm.czma001.czma00101;
      import java.io.PrintStream;

      public class czma00101 {
      boolean etalon = true;

      // definitions for invocations with many parameters
      boolean Zpar = false;
      byte Bpar = (byte)153;
      char Cpar = '\u03a9';
      float Fpar = 99.9F;
      double Dpar = 1e-9d;
      int Ipar = 0xCafe;
      long Jpar = 0x10000C0B0L;
      short Spar = (short)0xf0fe;
      Object testObject = this;

      // parameter passage error accumulator string
      String resPar = new String();

      // method with ten parameters
      boolean a1997(int i, short s, Object o, boolean z,
      byte b, char c, float f, double d, long j) {
      if (i != Ipar)
      resPar += "wrong int argument value:" + i + ", should be " + Ipar +"\n";
      if (s != Spar)
      resPar += "wrong short argument value:" + s + ", should be " + Spar +"\n";
      if (o != testObject)
      resPar += "wrong Object argument value:" + o + ", should be " + testObject +"\n";
      if (z != Zpar)
      resPar += "wrong boolean argument value:" + z + ", should be " + Zpar +"\n";
      if (b != Bpar)
      resPar += "wrong byte argument value:" + b + ", should be " + Bpar +"\n";
      if (c != Cpar)
      resPar += "wrong char argument value:" + c + ", should be " + Cpar +"\n";
      if (f != Fpar)
      resPar += "wrong float argument value:" + f + ", should be " + Fpar +"\n";
      if (d != Dpar)
      resPar += "wrong double argument value:" + d + ", should be " + Dpar +"\n";
      if (j != Jpar)
      resPar += "wrong long argument value:" + j + ", should be " + Jpar +"\n";
      return etalon;
      }

      native int f(boolean aa,
      int i, short s, Object o, boolean z, byte b,
      char c, float f, double d, long j);

      static {
      System.loadLibrary("test");
      }
      public static void main(String argv[]) {
      System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
      }
      public static int run(String argv[],PrintStream out) {
      int IresNat;
      int status = 0/*STATUS_PASSED*/;

      czma00101 ncli = new czma00101();
      IresNat = ncli.f(ncli.etalon,
      ncli.Ipar, ncli.Spar, ncli, ncli.Zpar, ncli.Bpar,
      ncli.Cpar, ncli.Fpar, ncli.Dpar, ncli.Jpar);

      if (IresNat != 0) {
      out.println("Native code returned bad status: " + IresNat);
      status = 2/*STATUS_FAILED*/;
      }
      if (ncli.resPar.length() != 0) {
      out.print(ncli.resPar);
      status = 2/*STATUS_FAILED*/;
      }
      return status;
      }
      }

      ::::::::::::::
      czma00101.c
      ::::::::::::::
      /* Ident: %Z%%M% %I% %E% */
      /* Copyright %G% Sun Microsystems, Inc. All Rights Reserved */

      #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

      JNIEXPORT jint JNICALL Java_javasoft_sqe_tests_vm_czma001_czma00101_czma00101_f(
      JNIEnv *env, jobject obj, jboolean aa,
      jint i, jshort s, jobject l, jboolean z, jbyte b,
      jchar c, jfloat f, jdouble d, jlong j) {

      jboolean resJ;
      /* java class */
      jclass jc;
      /* java method ID */
      jmethodID jmi;

      jvalue arr[9];
      arr[0].i = i;
      arr[1].s = s;
      arr[2].l = l;
      arr[3].z = z;
      arr[4].b = b;
      arr[5].c = c;
      arr[6].f = f;
      arr[7].d = d;
      arr[8].j = j;

      jc = JNI_ENV_PTR(env) -> GetObjectClass(JNI_ENV_ARG(env, obj));
      if ( jc == NULL) {
      return (3/*STATUS_FAILED*/);
      }
      jmi = JNI_ENV_PTR(env) ->
      GetMethodID(JNI_ENV_ARG(env, jc), "a1997" ,"(ISLjava/lang/Object;ZBCFDJ)Z");
      if ( jmi == NULL) {
      return (4/*STATUS_FAILED*/);
      }
      resJ = JNI_ENV_PTR(env) ->
      CallBooleanMethodA(JNI_ENV_ARG(env, obj), jmi, arr);
      if (resJ != aa) {
      printf("Bad result of CallBooleanMethodA\n");
      return (5);
      };

      return (0/*STATUS_PASSED*/);
      }

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

            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: