JDK-8037115 : Clarify exceptions thrown in JNI
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2014-03-11
  • Updated: 2014-03-19
  • Resolved: 2014-03-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
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.
Comments
After discussion with Roger Riggs, we agreed to close this as Not a Bug. The specification is actually clear that GetString[UTF8]Chars does not throw exceptions. The confusion was that the Parfait folks read Sheng Liang's jni.pdf rather than the specification in testing for expected results. So this is not a bug, it does not need to be fixed when resolving the specific non-null-terminated string question brought up in 6681965.
19-03-2014