Skip to content

Commit 14eba50

Browse files
committed
Consistent ExpressionException-style quoting of expression string and position
Issue: SPR-14942
1 parent b10045d commit 14eba50

File tree

8 files changed

+151
-143
lines changed

8 files changed

+151
-143
lines changed

spring-expression/src/main/java/org/springframework/expression/EvaluationException.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -26,7 +26,24 @@
2626
public class EvaluationException extends ExpressionException {
2727

2828
/**
29-
* Creates a new expression evaluation exception.
29+
* Create a new expression evaluation exception.
30+
* @param message description of the problem that occurred
31+
*/
32+
public EvaluationException(String message) {
33+
super(message);
34+
}
35+
36+
/**
37+
* Create a new expression evaluation exception.
38+
* @param message description of the problem that occurred
39+
* @param cause the underlying cause of this exception
40+
*/
41+
public EvaluationException(String message, Throwable cause) {
42+
super(message,cause);
43+
}
44+
45+
/**
46+
* Create a new expression evaluation exception.
3047
* @param position the position in the expression where the problem occurred
3148
* @param message description of the problem that occurred
3249
*/
@@ -35,7 +52,7 @@ public EvaluationException(int position, String message) {
3552
}
3653

3754
/**
38-
* Creates a new expression evaluation exception.
55+
* Create a new expression evaluation exception.
3956
* @param expressionString the expression that could not be evaluated
4057
* @param message description of the problem that occurred
4158
*/
@@ -44,7 +61,7 @@ public EvaluationException(String expressionString, String message) {
4461
}
4562

4663
/**
47-
* Creates a new expression evaluation exception.
64+
* Create a new expression evaluation exception.
4865
* @param position the position in the expression where the problem occurred
4966
* @param message description of the problem that occurred
5067
* @param cause the underlying cause of this exception
@@ -53,16 +70,4 @@ public EvaluationException(int position, String message, Throwable cause) {
5370
super(position, message, cause);
5471
}
5572

56-
/**
57-
* Creates a new expression evaluation exception.
58-
* @param message description of the problem that occurred
59-
*/
60-
public EvaluationException(String message) {
61-
super(message);
62-
}
63-
64-
public EvaluationException(String message, Throwable cause) {
65-
super(message,cause);
66-
}
67-
6873
}

spring-expression/src/main/java/org/springframework/expression/ExpressionException.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -20,75 +20,76 @@
2020
* Super class for exceptions that can occur whilst processing expressions.
2121
*
2222
* @author Andy Clement
23+
* @author Phil Webb
2324
* @since 3.0
2425
*/
2526
@SuppressWarnings("serial")
2627
public class ExpressionException extends RuntimeException {
2728

2829
protected String expressionString;
2930

30-
protected int position; // -1 if not known - but should be known in all reasonable cases
31+
protected int position; // -1 if not known; should be known in all reasonable cases
3132

3233

3334
/**
3435
* Construct a new expression exception.
35-
* @param expressionString the expression string
3636
* @param message a descriptive message
3737
*/
38-
public ExpressionException(String expressionString, String message) {
38+
public ExpressionException(String message) {
3939
super(message);
40-
this.position = -1;
41-
this.expressionString = expressionString;
4240
}
4341

4442
/**
4543
* Construct a new expression exception.
46-
* @param expressionString the expression string
47-
* @param position the position in the expression string where the problem occurred
4844
* @param message a descriptive message
45+
* @param cause the underlying cause of this exception
4946
*/
50-
public ExpressionException(String expressionString, int position, String message) {
51-
super(message);
52-
this.position = position;
53-
this.expressionString = expressionString;
47+
public ExpressionException(String message, Throwable cause) {
48+
super(message, cause);
5449
}
5550

5651
/**
5752
* Construct a new expression exception.
58-
* @param position the position in the expression string where the problem occurred
53+
* @param expressionString the expression string
5954
* @param message a descriptive message
6055
*/
61-
public ExpressionException(int position, String message) {
56+
public ExpressionException(String expressionString, String message) {
6257
super(message);
63-
this.position = position;
58+
this.expressionString = expressionString;
59+
this.position = -1;
6460
}
6561

6662
/**
6763
* Construct a new expression exception.
64+
* @param expressionString the expression string
6865
* @param position the position in the expression string where the problem occurred
6966
* @param message a descriptive message
70-
* @param cause the underlying cause of this exception
7167
*/
72-
public ExpressionException(int position, String message, Throwable cause) {
73-
super(message,cause);
68+
public ExpressionException(String expressionString, int position, String message) {
69+
super(message);
70+
this.expressionString = expressionString;
7471
this.position = position;
7572
}
7673

7774
/**
7875
* Construct a new expression exception.
76+
* @param position the position in the expression string where the problem occurred
7977
* @param message a descriptive message
8078
*/
81-
public ExpressionException(String message) {
79+
public ExpressionException(int position, String message) {
8280
super(message);
81+
this.position = position;
8382
}
8483

8584
/**
8685
* Construct a new expression exception.
86+
* @param position the position in the expression string where the problem occurred
8787
* @param message a descriptive message
8888
* @param cause the underlying cause of this exception
8989
*/
90-
public ExpressionException(String message, Throwable cause) {
90+
public ExpressionException(int position, String message, Throwable cause) {
9191
super(message,cause);
92+
this.position = position;
9293
}
9394

9495

@@ -107,8 +108,9 @@ public final int getPosition() {
107108
}
108109

109110
/**
110-
* Return the exception message. Since Spring 4.0 this method returns the
111-
* same result as {@link #toDetailedString()}.
111+
* Return the exception message.
112+
* As of Spring 4.0, this method returns the same result as {@link #toDetailedString()}.
113+
* @see #getSimpleMessage()
112114
* @see java.lang.Throwable#getMessage()
113115
*/
114116
@Override
@@ -123,11 +125,11 @@ public String getMessage() {
123125
public String toDetailedString() {
124126
if (this.expressionString != null) {
125127
StringBuilder output = new StringBuilder();
126-
output.append("Expression '");
128+
output.append("Expression [");
127129
output.append(this.expressionString);
128-
output.append("'");
129-
if (this.position != -1) {
130-
output.append(" @ ");
130+
output.append("]");
131+
if (this.position >= 0) {
132+
output.append(" @");
131133
output.append(this.position);
132134
}
133135
output.append(": ");
@@ -142,6 +144,7 @@ public String toDetailedString() {
142144
/**
143145
* Return the exception simple message without including the expression
144146
* that caused the failure.
147+
* @since 4.0
145148
*/
146149
public String getSimpleMessage() {
147150
return super.getMessage();

spring-expression/src/main/java/org/springframework/expression/ParseException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -26,7 +26,7 @@
2626
public class ParseException extends ExpressionException {
2727

2828
/**
29-
* Creates a new expression parsing exception.
29+
* Create a new expression parsing exception.
3030
* @param expressionString the expression string that could not be parsed
3131
* @param position the position in the expression string where the problem occurred
3232
* @param message description of the problem that occurred
@@ -36,7 +36,7 @@ public ParseException(String expressionString, int position, String message) {
3636
}
3737

3838
/**
39-
* Creates a new expression parsing exception.
39+
* Create a new expression parsing exception.
4040
* @param position the position in the expression string where the problem occurred
4141
* @param message description of the problem that occurred
4242
* @param cause the underlying cause of this exception
@@ -46,7 +46,7 @@ public ParseException(int position, String message, Throwable cause) {
4646
}
4747

4848
/**
49-
* Creates a new expression parsing exception.
49+
* Create a new expression parsing exception.
5050
* @param position the position in the expression string where the problem occurred
5151
* @param message description of the problem that occurred
5252
*/

spring-expression/src/main/java/org/springframework/expression/spel/SpelEvaluationException.java

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.expression.spel;
1718

1819
import org.springframework.expression.EvaluationException;
@@ -23,6 +24,7 @@
2324
* message. See {@link SpelMessage} for the list of all possible messages that can occur.
2425
*
2526
* @author Andy Clement
27+
* @author Juergen Hoeller
2628
* @since 3.0
2729
*/
2830
@SuppressWarnings("serial")
@@ -34,62 +36,46 @@ public class SpelEvaluationException extends EvaluationException {
3436

3537

3638
public SpelEvaluationException(SpelMessage message, Object... inserts) {
37-
super(message.formatMessage(0, inserts)); // TODO poor position information, can the callers not really supply something?
39+
super(message.formatMessage(inserts));
3840
this.message = message;
3941
this.inserts = inserts;
4042
}
4143

4244
public SpelEvaluationException(int position, SpelMessage message, Object... inserts) {
43-
super(position, message.formatMessage(position, inserts));
45+
super(position, message.formatMessage(inserts));
4446
this.message = message;
4547
this.inserts = inserts;
4648
}
4749

48-
public SpelEvaluationException(int position, Throwable cause,
49-
SpelMessage message, Object... inserts) {
50-
super(position,message.formatMessage(position,inserts),cause);
50+
public SpelEvaluationException(int position, Throwable cause, SpelMessage message, Object... inserts) {
51+
super(position, message.formatMessage(inserts),cause);
5152
this.message = message;
5253
this.inserts = inserts;
5354
}
5455

5556
public SpelEvaluationException(Throwable cause, SpelMessage message, Object... inserts) {
56-
super(message.formatMessage(0,inserts),cause);
57+
super(message.formatMessage(inserts), cause);
5758
this.message = message;
5859
this.inserts = inserts;
5960
}
6061

6162

6263
/**
63-
* @return a formatted message with inserts applied
64+
* Set the position in the related expression which gave rise to this exception.
6465
*/
65-
@Override
66-
public String getMessage() {
67-
if (this.message != null) {
68-
return this.message.formatMessage(this.position, this.inserts);
69-
}
70-
else {
71-
return super.getMessage();
72-
}
66+
public void setPosition(int position) {
67+
this.position = position;
7368
}
7469

7570
/**
76-
* @return the message code
71+
* Return the message code.
7772
*/
7873
public SpelMessage getMessageCode() {
7974
return this.message;
8075
}
8176

8277
/**
83-
* Set the position in the related expression which gave rise to this exception.
84-
*
85-
* @param position the position in the expression that gave rise to the exception
86-
*/
87-
public void setPosition(int position) {
88-
this.position = position;
89-
}
90-
91-
/**
92-
* @return the message inserts
78+
* Return the message inserts.
9379
*/
9480
public Object[] getInserts() {
9581
return this.inserts;

0 commit comments

Comments
 (0)