Use the same FindClass argument for Android and regular Java
authorMatt Corallo <git@bluematt.me>
Sun, 12 Dec 2021 18:44:34 +0000 (18:44 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 12 Dec 2021 18:47:59 +0000 (18:47 +0000)
Its unclear whether the android variant (no L prefix, ; suffix) was
ever tested on normal Java or not, but the existing code generates
a large volumes of warnings on OpenJDK 11 like:

WARNING in native method: JNI FindClass received a bad class descriptor "Lorg/ldk/impl/bindings$LDKEvent$PaymentReceived;".  A correct class descriptor has no leading "L" or trailing ";".  Incorrect descriptors will not be accepted in future releases.

java_strings.py

index 5ff98d9d4113a0c40cb11ee7b83ca77ad3d01f4a..95c65ce7bc9aa65ed58c135abb5c5bdc8b2355fe 100644 (file)
@@ -681,14 +681,11 @@ import javax.annotation.Nullable;
             out_c = out_c + "static jmethodID " + struct_name + "_" + var + "_meth = NULL;\n"
         out_c = out_c + self.c_fn_ty_pfx + "void JNICALL Java_org_ldk_impl_bindings_00024" + struct_name.replace("_", "_1") + "_init (" + self.c_fn_args_pfx + ") {\n"
         for var_name in variants:
-            out_c = out_c + "\t" + struct_name + "_" + var_name + "_class =\n"
-            if self.target == Target.ANDROID:
-                out_c = out_c + "\t\t(*env)->NewGlobalRef(env, (*env)->FindClass(env, \"org/ldk/impl/bindings$" + struct_name + "$" + var_name + "\"));\n"
-            else:
-                out_c = out_c + "\t\t(*env)->NewGlobalRef(env, (*env)->FindClass(env, \"Lorg/ldk/impl/bindings$" + struct_name + "$" + var_name + ";\"));\n"
-            out_c = out_c + "\tCHECK(" + struct_name + "_" + var_name + "_class != NULL);\n"
-            out_c = out_c + "\t" + struct_name + "_" + var_name + "_meth = (*env)->GetMethodID(env, " + struct_name + "_" + var_name + "_class, \"<init>\", \"(" + init_meth_jty_strs[var_name] + ")V\");\n"
-            out_c = out_c + "\tCHECK(" + struct_name + "_" + var_name + "_meth != NULL);\n"
+            out_c += "\t" + struct_name + "_" + var_name + "_class =\n"
+            out_c += "\t\t(*env)->NewGlobalRef(env, (*env)->FindClass(env, \"org/ldk/impl/bindings$" + struct_name + "$" + var_name + "\"));\n"
+            out_c += "\tCHECK(" + struct_name + "_" + var_name + "_class != NULL);\n"
+            out_c += "\t" + struct_name + "_" + var_name + "_meth = (*env)->GetMethodID(env, " + struct_name + "_" + var_name + "_class, \"<init>\", \"(" + init_meth_jty_strs[var_name] + ")V\");\n"
+            out_c += "\tCHECK(" + struct_name + "_" + var_name + "_meth != NULL);\n"
         out_c = out_c + "}\n"
         return out_c