{"record":{"id":"db4cd2fec6004fa7","repo":"openjdk/jdk","slug":"jvm-caught-asan-error","errorCode":null,"errorMessage":"JVM caught ASAN Error\n","messagePattern":"JVM caught ASAN Error\n","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/hotspot/share/sanitizers/address.cpp","lineNumber":50,"sourceCode":"\n#ifndef _WINDOWS\n#include <dlfcn.h>\n#include <stdio.h>\n\ntypedef void (*callback_setter_t) (void (*callback)(const char *));\nstatic callback_setter_t g_callback_setter = nullptr;\nstatic const char* g_report = nullptr;\n\nextern \"C\" void asan_error_callback(const char* report_text) {\n  // Please keep things very short and simple here and use as little\n  // as possible of any hotspot infrastructure. However shaky the JVM,\n  // we should always at least get the ASAN report on stderr.\n\n  // Note: this is threadsafe since ASAN synchronizes error reports\n  g_report = report_text;\n\n  // First, print off the bare error to stderr\n  fprintf(stderr, \"JVM caught ASAN Error\\n\");\n  fprintf(stderr, \"%s\\n\", report_text);\n\n  // Then, let normal JVM error handling run its due course.\n  fatal(\"ASAN Error\");\n}\n\nvoid Asan::initialize() {\n\n  // For documentation of __asan_set_error_report_callback() see asan_interface.h .\n  g_callback_setter = (callback_setter_t) dlsym(RTLD_DEFAULT, \"__asan_set_error_report_callback\");\n  if (g_callback_setter == nullptr) {\n    log_info(asan)(\"*** Failed to install JVM callback for ASAN. ASAN errors will not generate hs-err files. ***\");\n    return;\n  }\n\n  g_callback_setter(asan_error_callback);\n  log_info(asan)(\"JVM callback for ASAN errors successfully installed\");\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/hotspot/share/sanitizers/address.cpp#L32-L68","documentation":"The AddressSanitizer error-report callback installed by the JVM (asan_error_callback in hotspot/share/sanitizers/address.cpp). When a JVM is built with ASAN (--with-asan) and ASAN detects a memory error (use-after-free, buffer overflow, etc.), ASAN invokes this callback: it stores the report, prints 'JVM caught ASAN Error' plus the raw ASAN report to stderr, then calls fatal(\"ASAN Error\") so normal JVM error handling produces an hs-err file and terminates the process.","triggerScenarios":"Any memory error detected by ASAN in JVM native code during execution of an ASAN-instrumented libjvm: heap-buffer-overflow, use-after-free, stack-overflow, SEGV on wild pointer, container-overflow, etc. The message is the JVM-side wrapper; the real cause is in the ASAN report text printed on the following lines.","commonSituations":"Running tests against a --with-asan built JDK (used by Oracle/SAP CI and by developers hunting native memory bugs); a native library (JNI agent, instrumented JDK patch) introducing an out-of-bounds access; new HotSpot code under review being validated with ASAN.","solutions":["Read the full ASAN report printed immediately after this line — it names the error type, the faulting stack, and the allocation/free stacks","Reproduce under gdb/ASAN_OPTIONS=abort_on_error=1:symbolize=1 to get a debuggable stack with line info (build with --with-native-debug-symbols=yes)","Fix the actual out-of-bounds / lifetime bug in the native code the report points to (this message itself is not the bug, only the notification)","If the report points into a third-party JNI library, report to that library; if into the JDK, file a JDK bug with the hs-err file and reproduction"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"# Run ASAN JVM with tight options so reports are actionable:\nexport ASAN_OPTIONS=abort_on_error=1:detect_leaks=0:symbolize=1\n$JDK_ASAN/bin/java -version   # smoke-test before running real tests","typeGuard":null,"tryCatchPattern":"This message precedes fatal(\"ASAN Error\") — it cannot be caught. The 'catch' pattern is post-mortem: preserve the hs-err file and stderr ASAN report, then reproduce under gdb with ASAN_OPTIONS=abort_on_error=1 to break at the faulting access.","preventionTips":["Run new native (JNI/JVM) code under an --with-asan JDK build before shipping","Fix the underlying memory bug the report names; this callback only reports it","Attach allocation stacks: build with debug symbols so ASAN reports map to source lines"],"tags":["hotspot","asan","sanitizers","memory-safety","native","crash"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}