Skip to content

Commit 50f8b6b

Browse files
committed
Revised assertions and $[invocationTime] support for exceptionMessage
Issue: SPR-15763 (cherry picked from commit 19a8efc)
1 parent 121a3bf commit 50f8b6b

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

spring-aop/src/main/java/org/springframework/aop/interceptor/CustomizableTraceInterceptor.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -128,20 +128,20 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
128128
/**
129129
* The default message used for writing method entry messages.
130130
*/
131-
private static final String DEFAULT_ENTER_MESSAGE =
132-
"Entering method '" + PLACEHOLDER_METHOD_NAME + "' of class [" + PLACEHOLDER_TARGET_CLASS_NAME + "]";
131+
private static final String DEFAULT_ENTER_MESSAGE = "Entering method '" +
132+
PLACEHOLDER_METHOD_NAME + "' of class [" + PLACEHOLDER_TARGET_CLASS_NAME + "]";
133133

134134
/**
135135
* The default message used for writing method exit messages.
136136
*/
137-
private static final String DEFAULT_EXIT_MESSAGE =
138-
"Exiting method '" + PLACEHOLDER_METHOD_NAME + "' of class [" + PLACEHOLDER_TARGET_CLASS_NAME + "]";
137+
private static final String DEFAULT_EXIT_MESSAGE = "Exiting method '" +
138+
PLACEHOLDER_METHOD_NAME + "' of class [" + PLACEHOLDER_TARGET_CLASS_NAME + "]";
139139

140140
/**
141141
* The default message used for writing exception messages.
142142
*/
143-
private static final String DEFAULT_EXCEPTION_MESSAGE =
144-
"Exception thrown in method '" + PLACEHOLDER_METHOD_NAME + "' of class [" + PLACEHOLDER_TARGET_CLASS_NAME + "]";
143+
private static final String DEFAULT_EXCEPTION_MESSAGE = "Exception thrown in method '" +
144+
PLACEHOLDER_METHOD_NAME + "' of class [" + PLACEHOLDER_TARGET_CLASS_NAME + "]";
145145

146146
/**
147147
* The {@code Pattern} used to match placeholders.
@@ -182,14 +182,14 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
182182
* </ul>
183183
*/
184184
public void setEnterMessage(String enterMessage) throws IllegalArgumentException {
185-
Assert.hasText(enterMessage, "'enterMessage' must not be empty");
185+
Assert.hasText(enterMessage, "enterMessage must not be empty");
186186
checkForInvalidPlaceholders(enterMessage);
187187
Assert.doesNotContain(enterMessage, PLACEHOLDER_RETURN_VALUE,
188-
"enterMessage cannot contain placeholder [" + PLACEHOLDER_RETURN_VALUE + "]");
188+
"enterMessage cannot contain placeholder " + PLACEHOLDER_RETURN_VALUE);
189189
Assert.doesNotContain(enterMessage, PLACEHOLDER_EXCEPTION,
190-
"enterMessage cannot contain placeholder [" + PLACEHOLDER_EXCEPTION + "]");
190+
"enterMessage cannot contain placeholder " + PLACEHOLDER_EXCEPTION);
191191
Assert.doesNotContain(enterMessage, PLACEHOLDER_INVOCATION_TIME,
192-
"enterMessage cannot contain placeholder [" + PLACEHOLDER_INVOCATION_TIME + "]");
192+
"enterMessage cannot contain placeholder " + PLACEHOLDER_INVOCATION_TIME);
193193
this.enterMessage = enterMessage;
194194
}
195195

@@ -206,10 +206,10 @@ public void setEnterMessage(String enterMessage) throws IllegalArgumentException
206206
* </ul>
207207
*/
208208
public void setExitMessage(String exitMessage) {
209-
Assert.hasText(exitMessage, "'exitMessage' must not be empty");
209+
Assert.hasText(exitMessage, "exitMessage must not be empty");
210210
checkForInvalidPlaceholders(exitMessage);
211211
Assert.doesNotContain(exitMessage, PLACEHOLDER_EXCEPTION,
212-
"exitMessage cannot contain placeholder [" + PLACEHOLDER_EXCEPTION + "]");
212+
"exitMessage cannot contain placeholder" + PLACEHOLDER_EXCEPTION);
213213
this.exitMessage = exitMessage;
214214
}
215215

@@ -225,12 +225,10 @@ public void setExitMessage(String exitMessage) {
225225
* </ul>
226226
*/
227227
public void setExceptionMessage(String exceptionMessage) {
228-
Assert.hasText(exceptionMessage, "'exceptionMessage' must not be empty");
228+
Assert.hasText(exceptionMessage, "exceptionMessage must not be empty");
229229
checkForInvalidPlaceholders(exceptionMessage);
230230
Assert.doesNotContain(exceptionMessage, PLACEHOLDER_RETURN_VALUE,
231-
"exceptionMessage cannot contain placeholder [" + PLACEHOLDER_RETURN_VALUE + "]");
232-
Assert.doesNotContain(exceptionMessage, PLACEHOLDER_INVOCATION_TIME,
233-
"exceptionMessage cannot contain placeholder [" + PLACEHOLDER_INVOCATION_TIME + "]");
231+
"exceptionMessage cannot contain placeholder " + PLACEHOLDER_RETURN_VALUE);
234232
this.exceptionMessage = exceptionMessage;
235233
}
236234

@@ -262,17 +260,17 @@ protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throw
262260
stopWatch.stop();
263261
}
264262
exitThroughException = true;
265-
writeToLog(logger,
266-
replacePlaceholders(this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex);
263+
writeToLog(logger, replacePlaceholders(
264+
this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex);
267265
throw ex;
268266
}
269267
finally {
270268
if (!exitThroughException) {
271269
if (stopWatch.isRunning()) {
272270
stopWatch.stop();
273271
}
274-
writeToLog(logger,
275-
replacePlaceholders(this.exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis()));
272+
writeToLog(logger, replacePlaceholders(
273+
this.exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis()));
276274
}
277275
}
278276
}

0 commit comments

Comments
 (0)