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

getLastErrorString should avoid charset conversions

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 21
    • None
    • core-libs
    • None
    • b14
    • windows

      On Windows, JNU_ThrowByNameWithLastError calls getLastErrorString, which in turn calls FormatMessageA, which first retrieves a localized error message from the OS, then converts it from Unicode to the current (Windows) code page. Later the message is converted back to Unicode using JNU_NewStringPlatform.

      If the current code page cannot represent all characters in the Unicode message, some information will be lost. If JNU_NewStringPlatform uses a different encoding than Windows, the message may end up being completely different.

      We should use FormatMessageW to retrieve the message. This method returns the message in Unicode, which can then be used in JNI NewString without any conversions.

      There are other methods that also use getLastErrorString to retrieve error text; these include:
      JNU_ThrowByNameWithLastError
      JNU_ThrowIOExceptionWithLastError
      JNU_ThrowByNameWithMessageAndLastError
      NET_ThrowByNameWithLastError
      and a few others.

            djelinski Daniel Jelinski
            djelinski Daniel Jelinski
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: