<commit_before>#include <stdarg.h>
#include <string.h>

#include "JavaObject.h"

DEFINE_JAVA_CLASS_NAME(JavaObject, "");

JavaObject::JavaObject(jobject object) : object(object)
{
}

JavaObject::~JavaObject()
{
	if (object)
		getJNIEnv()->DeleteGlobalRef(object);
}

void JavaObject::setJObjectLocal(jobject object)
{
	setJObject(object);
	getJNIEnv()->DeleteLocalRef(object);
}

void JavaObject::setJObject(jobject object)
{
	// TODO: check class_name of jobject
	if (object)
		getJNIEnv()->DeleteGlobalRef(object);
	object = getJNIEnv()->NewGlobalRef(object);
}

jvalue JavaObject::invokeInstanceMethod(const char* name, const char* signature, ...) const
{
	JNIEnv* env = getJNIEnv();
	jvalue jval;
	jthrowable jexc = 0;
	va_list args;
	va_start(args, signature);
	::invokeMethodV(env, &jval, &jexc, INSTANCE, getJObject(), getJavaClassName(), name, signature, args);
	va_end(args);
	if (jexc)
		throw JavaException(jexc);
	return jval;
}

void JavaObject::constructNewObject(const char* signature, ...) const
{<commit_msg>Fix initialization of JavaObject<commit_after>#include <stdarg.h>
#include <string.h>

#include "JavaObject.h"

DEFINE_JAVA_CLASS_NAME(JavaObject, "");

JavaObject::JavaObject(jobject object) : object(object)
{
}

JavaObject::~JavaObject()
{
	if (object)
		getJNIEnv()->DeleteGlobalRef(object);
}

void JavaObject::setJObjectLocal(jobject object_)
{
	setJObject(object_);
	getJNIEnv()->DeleteLocalRef(object_);
}

void JavaObject::setJObject(jobject object_)
{
	// TODO: check class_name of jobject
	if (object)
		getJNIEnv()->DeleteGlobalRef(object);
	object = getJNIEnv()->NewGlobalRef(object_);
}

jvalue JavaObject::invokeInstanceMethod(const char* name, const char* signature, ...) const
{
	JNIEnv* env = getJNIEnv();
	jvalue jval;
	jthrowable jexc = 0;
	va_list args;
	va_start(args, signature);
	::invokeMethodV(env, &jval, &jexc, INSTANCE, getJObject(), getJavaClassName(), name, signature, args);
	va_end(args);
	if (jexc)
		throw JavaException(jexc);
	return jval;
}

void JavaObject::constructNewObject(const char* signature, ...) const
{
{'fraction_non_alphanumeric': 0.14657666345226616, 'fraction_numerical': 0.0009643201542912247, 'mean_word_length': 6.572992700729927, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6691840', 'n_tokens_mistral': 747, 'n_tokens_neox': 734, 'n_words': 149}