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

[JNI] The JNI Specification needs to address the limitations of integer UTF-8 String lengths

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • 23
    • hotspot
    • b14

      The GetStringUTFLength function returns the length as a jint (jsize) value and so is limited to returning at most Integer.MAX_VALUE. But a Java string can itself consist of Integer.MAX_VALUE characters, each of which may require more than one byte to represent them in modified UTF-8 format.** It follows then that this function cannot return the correct answer for all String values and yet the specification makes no mention of this, nor of any possible error to report if this situation is encountered.

      **The modified UTF-8 format used by the VM can require up to six bytes to represent one unicode character, but six byte characters are stored as UTF16 surrogate pairs. Hence the most bytes per character is 3, and so the maximum length is 3*Integer.MAX_VALUE. With compact strings this reduces to 2*Integer.MAX_VALUE.

            dholmes David Holmes
            dholmes David Holmes
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: