codeconsole opened a new pull request, #3267:
URL: https://github.com/apache/groovy/pull/3267

   https://issues.apache.org/jira/browse/GROOVY-12732
   
   When a script throws, the `groovy` command printed `SEVERE: Caught: {0}` and 
then the stack trace twice. `GroovyMain.run()` has called `LOGGER.log(ERROR, 
"Caught: {0}", e)` since GROOVY-11886. Because `e` is a `Throwable`, Java 
selects `System.Logger.log(Level, String, Throwable)` rather than `log(Level, 
String, Object...)`, so the placeholder is never filled. The logger also 
printed the full stack trace before `StackTraceUtils.deepSanitize` ran, so that 
copy ignored `-d`. `printStackTrace()` then printed the sanitized trace a 
second time.
   
   The message is now `"Caught: " + e`, the text the command printed before 
GROOVY-11886, and the trace is printed once by `printStackTrace()`, sanitized 
unless `-d` is given. The other logging calls with a `{0}` placeholder pass 
arguments that are not throwables and are not affected.
   
   Test: 
`GroovyMainTest.testUncaughtExceptionIsLoggedWithItsTextAndItsStackTracePrintedOnce`
 captures the `groovy.ui.GroovyMain` log records. It checks for one SEVERE 
record whose formatted message is `Caught: java.lang.IllegalStateException: 
boom` and which carries no throwable, and for exactly one printed trace. On 
master it fails with `'Caught: {0}'`. With the fix, `GroovyMainTest` passes 
locally (17 tests, 1 already `@Disabled`) on JDK 21.
   
   The same line is on `GROOVY_6_0_X`, so this could be backported for 6.0.1.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to