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

GetStringUTFLength returns one-too-long length

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1fcs
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Not verified

      Description



      Name: laC46010 Date: 01/23/97


      The test below shows that GetStringUTFLength returns length+1 as result.
      Particularly it returns 1 for empty string.

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

      >jnirun
      Wrong length of empty string: len1=0 len2=1
      Wrong length of ASCII string: len1=7 len2=8
      Wrong length of non-ASCII string: len1=25 len2=26

      ::::::::::::::
      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.gsul.gsul.gsul00101

      ::::::::::::::
      gsul00101.c
      ::::::::::::::
      /* File: %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_gsul_gsul_gsul00101_gsul00101lenJava
      (JNIEnv *env, jobject obj, jstring val) {
      const jbyte* larr;
      jboolean IsCopy;
      int i;
      int rlen = JNI_ENV_PTR(env) -> GetStringUTFLength(JNI_ENV_ARG(env, val));
      /* printf("Real len %d \n",rlen);
      larr = JNI_ENV_PTR(env) -> GetStringUTFChars(JNI_ENV_ARG(env, val), &IsCopy);
      printf("Bytes in Array from String:");
      for (i=0;i < rlen;i++) {
      printf(" %x",*(larr+i)&0xff);
      }
      printf("\n");
      */
      return rlen;
      }

      /* Temporary is commented because NewStringUTF works not correct

      JNIEXPORT jboolean JNICALL
      Java_javasoft_sqe_tests_vm_gsul001_gsul00101_gsul00101_gsul00101lenNative
      (JNIEnv *env, jobject obj, jstring val, jsize len) {
      jboolean IsCopy;
      jchar* larr = JNI_ENV_PTR(env) -> GetStringUTFChars(JNI_ENV_ARG(env, val),&IsCopy);
      jstring lstr = JNI_ENV_PTR(env) -> NewStringUTF(JNI_ENV_ARG(env, larr), len);
      return ((JNI_ENV_PTR(env) -> GetStringUTFLength(JNI_ENV_ARG(env, lstr)) != len)?JNI_FALSE:JNI_TRUE);
      }

      */
      #ifdef __cplusplus
      }
      #endif
      ::::::::::::::
      gsul00101.java
      ::::::::::::::
      //File: %Z%%M% %I% %E%
      //Copyright %G% Sun Microsystems, Inc. All Rights Reserved

      package javasoft.sqe.tests.vm.gsul.gsul;
      import java.io.PrintStream;


      public class gsul00101 {

        public static void main(String argv[])
        {
           System.exit(run() + 95/*STATUS_TEMP*/);
        }

        public native int gsul00101lenJava(String val);

        static {
          System.loadLibrary("test");
        }
          
        public static int run() {
          gsul00101 tob = new gsul00101();
          String lstr1 = new String("");
          String lstr2 = new String("ZYXWVUT");
          String lstr3 = new String("Z\u0000Y\u0080X\u06efW\u07ffV\u0800U\u5555T\uFFFFS");
          int reslen;
          int res = 0;
          try {
            reslen = tob.gsul00101lenJava(lstr1);
            if (lstr1.length() != reslen) {
              System.out.println("Wrong length of empty string: len1=" + lstr1.length() + " len2=" + reslen);
              res = 2 /*STATUS_FAILED*/;
            }
            reslen = tob.gsul00101lenJava(lstr2);
            if (lstr2.length() != reslen) {
              System.out.println("Wrong length of ASCII string: len1=" + lstr2.length() + " len2=" + reslen);
              res = 2 /*STATUS_FAILED*/;
            }
            reslen = tob.gsul00101lenJava(lstr3);
            if (25 != reslen) {
              System.out.println("Wrong length of non-ASCII string: len1=25 len2=" + reslen);
              res = 2 /*STATUS_FAILED*/;
            }
          } catch (Throwable e) {
            res = 2;
            System.out.println("Exception caught: " + e.getMessage() + ": " + e);
          }
        return res;
        }
      }

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: