Merge "Handle null FileDescriptors passed to native methods."
diff --git a/JNIHelp.cpp b/JNIHelp.cpp
index 22f95b6..88e968b 100644
--- a/JNIHelp.cpp
+++ b/JNIHelp.cpp
@@ -410,7 +410,12 @@
     if (fileDescriptorDescriptorField == nullptr) {
         InitFieldsAndMethods(e);
     }
-    (*env)->SetIntField(e, fileDescriptor, fileDescriptorDescriptorField, value);
+
+    if (fileDescriptor == nullptr) {
+        jniThrowNullPointerException(e, "null FileDescriptor");
+    } else {
+        e->SetIntField(fileDescriptor, fileDescriptorDescriptorField, value);
+    }
 }
 
 jlong jniGetOwnerIdFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor) {
diff --git a/include/nativehelper/JNIHelp.h b/include/nativehelper/JNIHelp.h
index 16747a9..c3c0ecc 100644
--- a/include/nativehelper/JNIHelp.h
+++ b/include/nativehelper/JNIHelp.h
@@ -94,7 +94,8 @@
 int jniGetFDFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor);
 
 /*
- * Sets the int fd in a java.io.FileDescriptor.
+ * Sets the int fd in a java.io.FileDescriptor.  Throws java.lang.NullPointerException
+ * if fileDescriptor is null.
  */
 void jniSetFileDescriptorOfFD(C_JNIEnv* env, jobject fileDescriptor, int value);