From 372756b6c360d5fb0ce657a84c779e1121cfbfde Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Fri, 3 Jul 2026 16:22:17 +0300 Subject: [PATCH] fix(detect_exceptions): allow non-indented continuation lines in Java exceptions Java exceptions with multi-line error messages have non-indented lines between the exception header and the stack trace. JIRA: LOG-9565 Signed-off-by: Vitalii Parfonov --- .../detect_exceptions/exception_detector.rs | 13 +++++ src/transforms/detect_exceptions/mod.rs | 51 +++++++++++++++++++ src/transforms/detect_exceptions/rules.rs | 3 ++ 3 files changed, 67 insertions(+) diff --git a/src/transforms/detect_exceptions/exception_detector.rs b/src/transforms/detect_exceptions/exception_detector.rs index f838619650521..24ace9570dbdf 100644 --- a/src/transforms/detect_exceptions/exception_detector.rs +++ b/src/transforms/detect_exceptions/exception_detector.rs @@ -292,6 +292,7 @@ mod exception_detector_tests { check_exception(java_simple_exception(), false); check_exception(java_complex_exception(), false); check_exception(java_nested_exception(), false); + check_exception(java_exception_with_non_nested_lines(), false); } const fn java_simple_exception() -> &'static str { @@ -339,6 +340,16 @@ Caused by: com.example.myproject.MyProjectServletException " } + const fn java_exception_with_non_nested_lines() -> &'static str { + " +java.sql.SQLException: Listener refused the connection with the following error: +ORA-12521, TNS:listener does not currently know of instance requested in connect descriptor + (CONNECTION_ID=r6n2ZPL0TqS/BLDhIydj+A==) + at oracle.jdbc.driver.T4CConnection.handleLogonNetException(T4CConnection.java:893) + at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:698) + " + } + const fn java_nested_exception() -> &'static str { " java.lang.RuntimeException: javax.mail.SendFailedException: Invalid Addresses; @@ -366,6 +377,8 @@ com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 <[REDACTED_EMAIL_ADDRESS at com.nethunt.crm.api.server.adminsync.AutomaticEmailFacade.sendWithSmtp(AutomaticEmailFacade.java:229) ... 12 more Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 <[REDACTED_EMAIL_ADDRESS]>... Relaying denied + at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:2064) + ... 12 more " } diff --git a/src/transforms/detect_exceptions/mod.rs b/src/transforms/detect_exceptions/mod.rs index ede8aef004de2..948c1ce362a50 100644 --- a/src/transforms/detect_exceptions/mod.rs +++ b/src/transforms/detect_exceptions/mod.rs @@ -399,4 +399,55 @@ Jul 09, 2015 3:23:29 PM com.google.devtools.search.cloud.feeder.MakeLog: Runtime assert_eq!(output_2["message"], java_simple_log.trim().into()); assert_eq!(output_2["counter"], Value::from(6)); } + + #[tokio::test] + async fn test_exception_with_non_nested_continuation_lines() { + let detect_exceptions = toml::from_str::( + r#" +languages = ["Java"] +"#, + ) + .unwrap() + .build(&TransformContext::default()) + .await + .unwrap(); + + let detect_exceptions = detect_exceptions.into_task(); + + let exception_with_continuation = "\ +java.sql.SQLException: Listener refused the connection with the following error: +ORA-12521, TNS:listener does not currently know of instance requested in connect descriptor + (CONNECTION_ID=r6n2ZPL0TqS/BLDhIydj+A==) + at oracle.jdbc.driver.T4CConnection.handleLogonNetException(T4CConnection.java:893) + at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:698)"; + let regular_log = "2026-06-02 13:55:59.506 INFO normal log message"; + + let lines = format!("{}\n{}", exception_with_continuation, regular_log); + + let mut counter = 0; + let input_events: Vec = lines + .split("\n") + .map(|line| { + let mut le = LogEvent::from(line); + le.insert("counter", counter); + counter += 1; + Event::Log(le) + }) + .collect(); + + let in_stream = Box::pin(stream::iter(input_events)); + let mut out_stream = detect_exceptions.transform_events(in_stream); + + let output_1 = out_stream.next().await.unwrap().into_log(); + assert_eq!( + output_1["message"], + exception_with_continuation.into(), + "All exception lines including non-nested continuations must be merged into one event" + ); + assert_eq!(output_1["counter"], Value::from(0)); + + let output_2 = out_stream.next().await.unwrap().into_log(); + assert_eq!(output_2["message"], regular_log.into()); + assert_eq!(output_2["counter"], Value::from(5)); + } } diff --git a/src/transforms/detect_exceptions/rules.rs b/src/transforms/detect_exceptions/rules.rs index f32d08b739bf4..5d82ddb034c53 100644 --- a/src/transforms/detect_exceptions/rules.rs +++ b/src/transforms/detect_exceptions/rules.rs @@ -106,6 +106,9 @@ fn java_rules() -> Vec> { r"^[\t ]*... \d+ (?:more|common frames omitted)", Java, ), + // Catch-all for non-indented continuation lines between the exception + // header and the stack trace (e.g. multi-line error messages). + rule(vec![JavaAfterException], r"^.+$", JavaAfterException), ] }