[PATCH] Add const to input parameter for JNU_IsInstanceOfByName

Andrew Luo andrewluotechnologies at outlook.com
Mon Jul 15 23:10:44 UTC 2019

Hi Everyone,

I'm making some const-correctness fixes to some downstream libraries that use JNU_* functions, and noticed that JNU_IsInstanceOfByName takes in the class name by char* instead of const char* when it does not need to modify the string.  It would be useful to change this so that we don't have to (unnecessarily) const-cast every time and can safely pass string literals to this function.  Patch is inline below - any comments/feedback welcome.



diff -r 70fab3a8ff02 src/java.base/share/native/libjava/jni_util.c
--- a/src/java.base/share/native/libjava/jni_util.c    Tue Jul 16 07:29:12 2019 +0900
+++ b/src/java.base/share/native/libjava/jni_util.c    Mon Jul 15 16:07:35 2019 -0700
@@ -1096,7 +1096,7 @@

-JNU_IsInstanceOfByName(JNIEnv *env, jobject object, char* classname)
+JNU_IsInstanceOfByName(JNIEnv *env, jobject object, const char* classname)
     jclass cls;
     if ((*env)->EnsureLocalCapacity(env, 1) < 0)
diff -r 70fab3a8ff02 src/java.base/share/native/libjava/jni_util.h
--- a/src/java.base/share/native/libjava/jni_util.h    Tue Jul 16 07:29:12 2019 +0900
+++ b/src/java.base/share/native/libjava/jni_util.h    Mon Jul 15 16:07:35 2019 -0700
@@ -208,7 +208,7 @@
  * has been thrown.
-JNU_IsInstanceOfByName(JNIEnv *env, jobject object, char *classname);
+JNU_IsInstanceOfByName(JNIEnv *env, jobject object, const char *classname);

/* Get or set class and instance fields.

More information about the core-libs-dev mailing list