From 5a36652b205892666133bed19d3887342f249194 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Thu, 7 Mar 2024 12:32:22 +0100 Subject: [PATCH] use e.printStackTrace(PrintWriter) as suggested by @beikov --- .../hibernate/processor/HibernateProcessor.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java index 06bc2bcaf5..03a47ddcb5 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/HibernateProcessor.java @@ -25,7 +25,8 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.tools.Diagnostic; -import java.util.Arrays; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -247,19 +248,15 @@ public class HibernateProcessor extends AbstractProcessor { createMetaModelClasses(); } catch (Exception e) { - final StringBuffer b = new StringBuffer(); - Arrays.stream(e.getStackTrace()) - .forEach(stackTraceElement -> { - b.append(stackTraceElement); - b.append('\n'); - }); + final StringWriter stack = new StringWriter(); + e.printStackTrace( new PrintWriter( stack) ); final Throwable cause = e.getCause(); final String message = cause != null && cause != e ? e.getMessage() + " caused by " + cause.getMessage() : e.getMessage(); - context.logMessage( Diagnostic.Kind.ERROR, "Error generating JPA metamodel: " + message ); - context.logMessage( Diagnostic.Kind.ERROR, b.toString() ); + context.logMessage( Diagnostic.Kind.ERROR, "Error running Hibernate processor: " + message ); + context.logMessage( Diagnostic.Kind.ERROR, stack.toString() ); } } return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;