Skip to content

Commit

Permalink
Refactor exception resolver initialization
Browse files Browse the repository at this point in the history
Removed the dependency on logger tracing for computing ExceptionResolver. Simplified method calls to static methods of ExceptionResolvers, ensuring consistent behavior regardless of logging settings. This should improve readability and maintainability of the configuration code.
  • Loading branch information
caring-coder committed Sep 22, 2024
1 parent 580081a commit e27a215
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class DocxStamperConfiguration
private boolean replaceUnresolvedExpressions = false;
private String unresolvedExpressionsDefaultValue = null;
private SpelParserConfiguration spelParserConfiguration = new SpelParserConfiguration();
private ExceptionResolver exceptionResolver = computeExceptionResolver(logger.isTraceEnabled());
private ExceptionResolver exceptionResolver = computeExceptionResolver();

/**
* Creates a new configuration with default values.
Expand Down Expand Up @@ -102,14 +102,14 @@ public boolean isFailOnUnresolvedExpression() {
@Deprecated(since = "2.5", forRemoval = true) @Override
public DocxStamperConfiguration setFailOnUnresolvedExpression(boolean failOnUnresolvedExpression) {
this.failOnUnresolvedExpression = failOnUnresolvedExpression;
this.exceptionResolver = computeExceptionResolver(logger.isTraceEnabled());
this.exceptionResolver = computeExceptionResolver();
return this;
}

private ExceptionResolver computeExceptionResolver(boolean tracing) {
if (failOnUnresolvedExpression) return new ExceptionResolvers.ThrowingResolver(tracing);
if (replaceWithDefaultOnError()) return new ExceptionResolvers.DefaultingResolver(replacementDefault(), tracing);
return new ExceptionResolvers.PassingResolver(tracing);
private ExceptionResolver computeExceptionResolver() {
if (failOnUnresolvedExpression) return ExceptionResolvers.throwing();
if (replaceWithDefaultOnError()) return ExceptionResolvers.defaulting(replacementDefault());
return ExceptionResolvers.passing();
}

private boolean replaceWithDefaultOnError() {
Expand Down Expand Up @@ -161,7 +161,7 @@ private String replacementDefault() {
@Deprecated(since = "2.5", forRemoval = true) @Override
public DocxStamperConfiguration unresolvedExpressionsDefaultValue(String unresolvedExpressionsDefaultValue) {
this.unresolvedExpressionsDefaultValue = unresolvedExpressionsDefaultValue;
this.exceptionResolver = computeExceptionResolver(logger.isTraceEnabled());
this.exceptionResolver = computeExceptionResolver();
return this;
}

Expand All @@ -176,7 +176,7 @@ public DocxStamperConfiguration unresolvedExpressionsDefaultValue(String unresol
@Deprecated(since = "2.5", forRemoval = true) @Override
public DocxStamperConfiguration replaceUnresolvedExpressions(boolean replaceUnresolvedExpressions) {
this.replaceUnresolvedExpressions = replaceUnresolvedExpressions;
this.exceptionResolver = computeExceptionResolver(logger.isTraceEnabled());
this.exceptionResolver = computeExceptionResolver();
return this;
}

Expand All @@ -192,7 +192,7 @@ public DocxStamperConfiguration replaceUnresolvedExpressions(boolean replaceUnre
@Deprecated(since = "2.5", forRemoval = true) @Override
public DocxStamperConfiguration leaveEmptyOnExpressionError(boolean leaveEmpty) {
this.leaveEmptyOnExpressionError = leaveEmpty;
this.exceptionResolver = computeExceptionResolver(logger.isTraceEnabled());
this.exceptionResolver = computeExceptionResolver();
return this;
}

Expand Down

0 comments on commit e27a215

Please sign in to comment.