<commit_before>#include <traildb.h>
#include "traildb-java.h"


jfieldID FID_traildb_TrailDB_db;


JNIEXPORT void JNICALL Java_traildb_TrailDB_init(JNIEnv *env, jobject obj, jstring root) {
	jclass exc;

	tdb_error err;
	const char *tgt_root;
	tdb *db;

	// Get strings

	tgt_root = (*env)->GetStringUTFChars(env, root, NULL);

	// Initialize tdb

	db = tdb_init();

	// Open tdb

	if ((err = tdb_open(db, tgt_root))) {
		exc = (*env)->FindClass(env, "java/io/FileNotFoundException");
		if (exc == NULL) {
			/* Could not find the exception - We are in so much trouble right now */
			exit(1);
		}
		(*env)->ThrowNew(env, exc, tdb_error_str(err));
		return;
	}

	// Release strings

	(*env)->ReleaseStringUTFChars(env, root, tgt_root);

	// Store db pointer

	(*env)->SetLongField(env, obj, FID_traildb_TrailDB_db, (long) db);<commit_msg>Always release strings even when there is an error opening tdb<commit_after>#include <traildb.h>
#include "traildb-java.h"


jfieldID FID_traildb_TrailDB_db;


JNIEXPORT void JNICALL Java_traildb_TrailDB_init(JNIEnv *env, jobject obj, jstring root) {
	jclass exc;

	tdb_error err;
	const char *tgt_root;
	tdb *db;

	// Get strings

	tgt_root = (*env)->GetStringUTFChars(env, root, NULL);

	// Initialize tdb

	db = tdb_init();

	// Open tdb

	err = tdb_open(db, tgt_root);

	// Release strings

	(*env)->ReleaseStringUTFChars(env, root, tgt_root);

	if (err) {
        exc = (*env)->FindClass(env, "java/io/FileNotFoundException");
        if (exc == NULL) {
            /* Could not find the exception - We are in so much trouble right now */
            exit(1);
        }
        (*env)->ThrowNew(env, exc, tdb_error_str(err));
        return;
    }

	// Store db pointer

	(*env)->SetLongField(env, obj, FID_traildb_TrailDB_db, (long) db);
{'fraction_non_alphanumeric': 0.1386861313868613, 'fraction_numerical': 0.0011229646266142617, 'mean_word_length': 3.557544757033248, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6252960', 'n_tokens_mistral': 711, 'n_tokens_neox': 669, 'n_words': 164}