This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch stacked/build-report in repository https://gitbox.apache.org/repos/asf/maven.git
commit 062b1c9ca5aa1c1c7c538e44887a3f680783bd57 Author: Guillaume Nodet <[email protected]> AuthorDate: Thu Nov 12 14:05:13 2026 +0000 fix: cap throwableToString() at 50 lines and clarify BuildReportJsonWriter Javadoc --- .../maven/internal/build/BuildReportJsonWriter.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/impl/maven-core/src/main/java/org/apache/maven/internal/build/BuildReportJsonWriter.java b/impl/maven-core/src/main/java/org/apache/maven/internal/build/BuildReportJsonWriter.java index 8d1a8e5747..df88317aa7 100644 --- a/impl/maven-core/src/main/java/org/apache/maven/internal/build/BuildReportJsonWriter.java +++ b/impl/maven-core/src/main/java/org/apache/maven/internal/build/BuildReportJsonWriter.java @@ -40,8 +40,9 @@ * appended at the end of each object. * <p> * Use {@link #write(Writer, BuildReport)} to write directly to any {@link Writer} - * (e.g. a {@code BufferedWriter} wrapping an {@code OutputStream}) without retaining - * the JSON string after the write completes. The {@link #toJson(BuildReport)} convenience + * (e.g. a {@code BufferedWriter} wrapping an {@code OutputStream}); the caller does not + * need to retain a reference to the JSON string after the write completes (the string is + * built internally and discarded). The {@link #toJson(BuildReport)} convenience * method is provided for testing and in-process consumers that need the string. */ final class BuildReportJsonWriter { @@ -475,6 +476,17 @@ private static void writeIndent(StringBuilder sb, int level) { private static String throwableToString(Throwable t) { StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); - return sw.toString(); + String full = sw.toString(); + // Cap at 50 lines to prevent huge JSON output from deeply nested exceptions + String[] lines = full.split("\r?\n"); + if (lines.length <= 50) { + return full.replace("\r\n", "\n"); + } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 50; i++) { + sb.append(lines[i]).append('\n'); + } + sb.append("... ").append(lines.length - 50).append(" more lines truncated"); + return sb.toString(); } }
