Skip to content

Commit e26e1ea

Browse files
committed
fix(jni): update FindClass FQNs for classes moved in the layered restructure
JNI_OnLoad resolves a handful of Java classes by hardcoded path via env->FindClass(...). The layered restructure moved two of them into subpackages, but the C++ paths still pointed at the old flat package, so once the native library actually loaded (after the LlamaLoader resource-path fix), JNI_OnLoad failed at load time with NoClassDefFoundError: net/ladenthin/llama/LogLevel and every native-backed Java test errored in LlamaModel.<clinit>. Corrected the stale paths to match the current packages: - net/ladenthin/llama/LlamaException -> net/ladenthin/llama/exception/LlamaException - net/ladenthin/llama/LogLevel -> net/ladenthin/llama/value/LogLevel (FindClass + the four GetStaticFieldID "L...;" field signatures) LlamaModel (root) and args/LogFormat were already correct; LoadProgressCallback appears only in a comment in the generated jllama.h (regenerated by javac -h), not in a FindClass, so it needs no change. Verified locally: incremental native rebuild + forcing LlamaModel.<clinit> (System.load -> JNI_OnLoad) now completes with no NoClassDefFoundError — the JNI class lookups resolve. Same stale-FQN-after-restructure class as the LlamaLoader resource-path, spotbugs-exclude, PIT-target and CMake-OSInfo repairs.
1 parent b4443b1 commit e26e1ea

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/main/cpp/jllama.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
479479
c_integer = env->FindClass("java/lang/Integer");
480480
c_float = env->FindClass("java/lang/Float");
481481
c_biconsumer = env->FindClass("java/util/function/BiConsumer");
482-
c_llama_error = env->FindClass("net/ladenthin/llama/LlamaException");
483-
c_log_level = env->FindClass("net/ladenthin/llama/LogLevel");
482+
c_llama_error = env->FindClass("net/ladenthin/llama/exception/LlamaException");
483+
c_log_level = env->FindClass("net/ladenthin/llama/value/LogLevel");
484484
c_log_format = env->FindClass("net/ladenthin/llama/args/LogFormat");
485485
c_error_oom = env->FindClass("java/lang/OutOfMemoryError");
486486

@@ -527,10 +527,10 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
527527
// find fields
528528
f_model_pointer = env->GetFieldID(c_llama_model, "ctx", "J");
529529
f_utf_8 = env->GetStaticFieldID(c_standard_charsets, "UTF_8", "Ljava/nio/charset/Charset;");
530-
f_log_level_debug = env->GetStaticFieldID(c_log_level, "DEBUG", "Lnet/ladenthin/llama/LogLevel;");
531-
f_log_level_info = env->GetStaticFieldID(c_log_level, "INFO", "Lnet/ladenthin/llama/LogLevel;");
532-
f_log_level_warn = env->GetStaticFieldID(c_log_level, "WARN", "Lnet/ladenthin/llama/LogLevel;");
533-
f_log_level_error = env->GetStaticFieldID(c_log_level, "ERROR", "Lnet/ladenthin/llama/LogLevel;");
530+
f_log_level_debug = env->GetStaticFieldID(c_log_level, "DEBUG", "Lnet/ladenthin/llama/value/LogLevel;");
531+
f_log_level_info = env->GetStaticFieldID(c_log_level, "INFO", "Lnet/ladenthin/llama/value/LogLevel;");
532+
f_log_level_warn = env->GetStaticFieldID(c_log_level, "WARN", "Lnet/ladenthin/llama/value/LogLevel;");
533+
f_log_level_error = env->GetStaticFieldID(c_log_level, "ERROR", "Lnet/ladenthin/llama/value/LogLevel;");
534534
f_log_format_json = env->GetStaticFieldID(c_log_format, "JSON", "Lnet/ladenthin/llama/args/LogFormat;");
535535
f_log_format_text = env->GetStaticFieldID(c_log_format, "TEXT", "Lnet/ladenthin/llama/args/LogFormat;");
536536

0 commit comments

Comments
 (0)