From d44f06ee0d09a1671bda5a0c4507fc0fc69c93f8 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 9 Nov 2020 11:08:34 +0100 Subject: [PATCH] Breaking the exception cycle --- .../internal/tech/BuildUnstableException.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/releaser-core/src/main/java/releaser/internal/tech/BuildUnstableException.java b/releaser-core/src/main/java/releaser/internal/tech/BuildUnstableException.java index 68f51834..306b1cdb 100644 --- a/releaser-core/src/main/java/releaser/internal/tech/BuildUnstableException.java +++ b/releaser-core/src/main/java/releaser/internal/tech/BuildUnstableException.java @@ -19,12 +19,22 @@ package releaser.internal.tech; import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; + +/** + * Exception to be thrown if one wants to continue with the build and throw this exception + * at the end of the release. + * + * @author Marcin Grzejszczak + */ /** * Exception to be thrown if one wants to continue with the build and throw this exception * at the end of the release. @@ -52,13 +62,14 @@ public class BuildUnstableException extends RuntimeException implements Serializ private final List exceptions = new ArrayList<>(); public BuildUnstableException(Throwable cause) { - super(cause); + super(breakReferenceChain(cause)); log.warn("\n\n" + DESCRIPTION, cause); - this.exceptions.add(cause); + this.exceptions.add((breakReferenceChain(cause))); } public BuildUnstableException(String message, List throwables) { - this(throwables); + this(throwables.stream().map(BuildUnstableException::breakReferenceChain) + .collect(Collectors.toList())); log.warn("\n\n" + DESCRIPTION + message + " with causes " + throwables); } @@ -66,6 +77,15 @@ public class BuildUnstableException extends RuntimeException implements Serializ public BuildUnstableException() { } + private static Throwable breakReferenceChain(Throwable cause) { + if (cause instanceof HttpServerErrorException + || cause instanceof HttpClientErrorException) { + return new RuntimeException( + "[Breaking self reference chain] " + cause.toString()); + } + return cause; + } + @JsonCreator public BuildUnstableException(@JsonProperty List throwables) { this.exceptions.addAll(throwables);