Skip to content

Commit 3b141a8

Browse files
committedFeb 28, 2025··
[138] Check if the stack trace is empty before attempting to copy it.
Signed-off-by: James R. Perkins <[email protected]>
1 parent 7324138 commit 3b141a8

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed
 

‎processor/pom.xml

+13
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,19 @@
196196
<expressionPropertiesPath>${expression.properties.path}</expressionPropertiesPath>
197197
</systemPropertyVariables>
198198
</configuration>
199+
<executions>
200+
<execution>
201+
<id>no-stack-trace</id>
202+
<goals>
203+
<goal>test</goal>
204+
</goals>
205+
<phase>test</phase>
206+
<configuration>
207+
<argLine>-XX:-StackTraceInThrowable</argLine>
208+
<groups>NoStackTrace</groups>
209+
</configuration>
210+
</execution>
211+
</executions>
199212
</plugin>
200213
</plugins>
201214
</build>

‎processor/src/main/java/org/jboss/logging/processor/generator/model/ImplementationClassModel.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,8 @@ private JCall getCopyStackMethod(final JClassDef classDef) {
679679
sourceFile._import(arrays);
680680
final JExpr e = $v(param);
681681
final JVarDeclaration st = body.var(FINAL, $t(StackTraceElement.class).array(), "st", e.call("getStackTrace"));
682-
body.add(e.call("setStackTrace")
682+
// Check if the stack trace is an empty array, if not copy the stack trace minus 1
683+
body._if($v(st).field("length").gt(JExpr.ZERO)).add(e.call("setStackTrace")
683684
.arg(arrays.call("copyOfRange").arg($v(st)).arg(JExpr.ONE).arg($v(st).field("length"))));
684685
}
685686
return JExprs.call(methodName);

‎processor/src/test/java/org/jboss/logging/processor/generated/tests/ThrowableSignatureTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@
2424
import org.jboss.logging.processor.generated.SignatureMessages.RedirectException;
2525
import org.jboss.logging.processor.generated.SignatureMessages.TestException;
2626
import org.junit.jupiter.api.Assertions;
27+
import org.junit.jupiter.api.Tag;
2728
import org.junit.jupiter.api.Test;
2829

2930
/**
3031
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
3132
*/
33+
@Tag("NoStackTrace")
3234
public class ThrowableSignatureTest {
3335

3436
@Test
3537
public void testSignatures() {
36-
@SuppressWarnings("RedundantStringFormatCall")
3738
final String formattedMessage = String.format(SignatureMessages.TEST_MSG);
3839
final RuntimeException cause = new RuntimeException("This was the cause");
3940

0 commit comments

Comments
 (0)
Please sign in to comment.