G
YouTube TikTok Games
Skip to content

GROOVY-12732: log the text of an uncaught script exception, and print its trace once - #3267

Open
codeconsole wants to merge 3 commits into
apache:masterfrom
codeconsole:fix/groovy-12732-groovymain-caught
Open

codeconsole wants to merge 3 commits into
apache:masterfrom
codeconsole:fix/groovy-12732-groovymain-caught

Conversation

@codeconsole

@codeconsole codeconsole commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

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 message is never formatted. 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 same cause affected one other call. GROOVY-11886 doubled the apostrophe in XStreamUtils.serialize's warning for MessageFormat, LOGGER.log(WARNING, "Couldn''t write to " + name + ".xml", e). That message is logged with its Throwable, so it is not formatted either, and the warning read Couldn''t write to .... The second commit writes a plain apostrophe. Every other logging call with a {0} placeholder or a doubled quote passes arguments that are not throwables, so MessageFormat does format it. The third commit only shortens the comment from the first.

Tests, each seen failing before its fix and passing after:

  • 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}'.
  • XStreamUtilsTest.dumpThatCannotBeWrittenIsReportedWithItsCause serializes into a directory that does not exist. It checks for one WARNING record whose formatted message is Couldn't write to <name>.xml and which carries the IOException.

./gradlew :test --tests 'groovy.ui.*' --tests 'org.codehaus.groovy.control.*' passes locally on JDK 21: 267 tests in 20 classes, 1 skipped (already @Disabled).

The same lines are on GROOVY_6_0_X, so this could be backported for 6.0.1.

… its trace once

GroovyMain.run() logged LOGGER.log(ERROR, "Caught: {0}", e). With a Throwable argument Java selects
System.Logger.log(Level, String, Throwable), so the placeholder was never filled and the logger printed the
full stack trace before StackTraceUtils.deepSanitize ran; printStackTrace() then printed the sanitized trace
a second time. The message is now "Caught: " + e, as before GROOVY-11886, and the trace is printed once,
sanitized unless -d is given.
… apostrophe

XStreamUtils.serialize logged LOGGER.log(WARNING, "Couldn''t write to " + name + ".xml", e). GROOVY-11886
doubled the quote for MessageFormat, but a message logged with a Throwable is not formatted, so the warning
read "Couldn''t write to ...". It is the same cause as the unfilled {0} in GroovyMain.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.4173%. Comparing base (cb1b208) to head (bad60e6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #3267        +/-   ##
==================================================
+ Coverage     74.4126%   74.4173%   +0.0047%     
- Complexity      44372      44379         +7     
==================================================
  Files            1699       1699                
  Lines          151051     151067        +16     
  Branches        28783      28790         +7     
==================================================
+ Hits           112401     112420        +19     
+ Misses          28376      28373         -3     
  Partials        10274      10274                
Files with missing lines Coverage Δ
src/main/java/groovy/ui/GroovyMain.java 68.8406% <100.0000%> (+1.8116%) ⬆️
...java/org/codehaus/groovy/control/XStreamUtils.java 58.5366% <100.0000%> (+7.3171%) ⬆️

... and 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@testlens-app

testlens-app Bot commented Nov 8, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: bad60e6
▶️ Tests: 130225 executed
⚪️ Checks: 26/26 completed


Learn more about TestLens at testlens.app/docs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants