[Java] Print error stack trace when tests fail
[ldk-java] / java_strings.py
index fe3b498181ebf1d67ee054c3f16c47605ea3ebc5..7e35d17529d0e8ea127c25e104b0f73996a8f3da 100644 (file)
@@ -72,6 +72,7 @@ public class bindings {
                // Fetching the LDK versions from C also checks that the header and binaries match
                System.err.println("Loaded LDK-Java Bindings " + version.get_ldk_java_bindings_version() + " with LDK " + get_ldk_version() + " and LDK-C-Bindings " + get_ldk_c_bindings_version());
        }
+       public static void run_statics() { /* Useful to force the statics to run */ }
        static native void init(java.lang.Class c);
        static native void init_class_cache();
        static native String get_lib_version_string();
@@ -861,7 +862,7 @@ import javax.annotation.Nullable;
             out_c = out_c + "\t\tcase %d: return %s;\n" % (ord_v, var)
             ord_v = ord_v + 1
         out_java_enum = out_java_enum + "\t; static native void init();\n"
-        out_java_enum = out_java_enum + "\tstatic { init(); }\n"
+        out_java_enum = out_java_enum + "\tstatic { org.ldk.impl.bindings.run_statics(); init(); }\n"
         out_java_enum = out_java_enum + "}"
         out_java = out_java + "\tstatic { " + struct_name + ".values(); /* Force enum statics to run */ }\n"
         out_c += "\t}\n"
@@ -1389,7 +1390,7 @@ import javax.annotation.Nullable;
         out_opaque_struct_human += self.hu_struct_file_prefix
         out_opaque_struct_human += "\n/**\n * " + struct_doc_comment.replace("\n", "\n * ") + "\n */\n"
         out_opaque_struct_human += "@SuppressWarnings(\"unchecked\") // We correctly assign various generic arrays\n"
-        hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDK", "")
+        hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC4Tuple", "FourTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDK", "")
         out_opaque_struct_human += ("public class " + hu_name + " extends CommonBase")
         if struct_name.startswith("LDKLocked") or struct_name.startswith("LDKReadOnly"):
             out_opaque_struct_human += (" implements AutoCloseable")
@@ -1417,6 +1418,9 @@ import javax.annotation.Nullable;
         java_hu_struct += "\tprotected void finalize() throws Throwable {\n"
         java_hu_struct += "\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); } super.finalize();\n"
         java_hu_struct += "\t}\n\n"
+        java_hu_struct += "\tprotected void force_free() {\n" # Used by NioPeerHandler
+        java_hu_struct += "\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); ptr = 0; }\n"
+        java_hu_struct += "\t}\n\n"
         java_hu_struct += "\tstatic " + human_ty + " constr_from_ptr(long ptr) {\n"
         java_hu_struct += "\t\tif (bindings." + struct_name.replace("LDK", "") + "_is_ok(ptr)) {\n"
         java_hu_struct += "\t\t\treturn new " + human_ty + "_OK(null, ptr);\n"