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

Clarify exceptions thrown in JNI

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: 9
    • Component/s: hotspot
    • Labels:

      Description

      The specification for GetString[UTF]Chars is ambiguous ( the Sheng Liang JNI book is at odds with the online specification ). It is not clear if there is a JNI pending exception if the function returns NULL.
      To ensure that an exception is thrown the following pattern (or similar) needs to be used.

            if (obj == NULL) {
                if (!(*env)->ExceptionCheck(env))
                    JNU_ThrowOutOfMemoryError(env, NULL);
                return NULL;
           }

      Since both out of memory and throwing exceptions is rare supplying extra code to check
      for conditions that do not occur is wasteful.

      Please clarify the JNI specification.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                rriggs Roger Riggs
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: