diff --git a/extension/android/executorch_android/src/main/java/org/pytorch/executorch/ExecutorchRuntimeException.java b/extension/android/executorch_android/src/main/java/org/pytorch/executorch/ExecutorchRuntimeException.java index e180efcdfca..c036ecefa76 100644 --- a/extension/android/executorch_android/src/main/java/org/pytorch/executorch/ExecutorchRuntimeException.java +++ b/extension/android/executorch_android/src/main/java/org/pytorch/executorch/ExecutorchRuntimeException.java @@ -75,6 +75,7 @@ public class ExecutorchRuntimeException extends RuntimeException { } static class ErrorHelper { + private static final boolean ENABLE_READ_LOG_BUFFER = false; // Reusable StringBuilder instance private static final StringBuilder sb = new StringBuilder(); @@ -92,14 +93,15 @@ static String formatMessage(int errorCode, String details) { .append("] ") .append(baseMessage) .append(": ") - .append(details) - .append("\nDetailed Logs:\n"); - - try { - String[] logEntries = readLogBuffer(); // JNI call - formatLogEntries(sb, logEntries); - } catch (Exception e) { - sb.append("Failed to retrieve detailed logs: ").append(e.getMessage()); + .append(details); + if (ENABLE_READ_LOG_BUFFER) { + try { + sb.append("\nDetailed Logs:\n"); + String[] logEntries = readLogBuffer(); // JNI call + formatLogEntries(sb, logEntries); + } catch (Exception e) { + sb.append("Failed to retrieve detailed logs: ").append(e.getMessage()); + } } return sb.toString(); diff --git a/extension/android/jni/jni_helper.cpp b/extension/android/jni/jni_helper.cpp index a8fb2aeddcf..b92856bacb2 100644 --- a/extension/android/jni/jni_helper.cpp +++ b/extension/android/jni/jni_helper.cpp @@ -19,11 +19,12 @@ void throwExecutorchException(uint32_t errorCode, const std::string& details) { "org/pytorch/executorch/ExecutorchRuntimeException"); // Find the static factory method: makeExecutorchException(int, String) - static auto makeExceptionMethod = exceptionClass->getStaticMethod< - facebook::jni::local_ref( - int, facebook::jni::alias_ref)>( - "makeExecutorchException", - "(ILjava/lang/String;)Lorg/pytorch/executorch/ExecutorchRuntimeException;"); + static auto makeExceptionMethod = + exceptionClass + ->getStaticMethod( + int, facebook::jni::alias_ref)>( + "makeExecutorchException", + "(ILjava/lang/String;)Ljava/lang/RuntimeException;"); auto jDetails = facebook::jni::make_jstring(details); // Call the factory method to create the exception object