Skip to content

Commit 8458cee

Browse files
committed
fix: replace string matching with getMessageCode in SpEL exception handling for improved clarity
- Used `METHOD_NOT_FOUND` constant instead of string matching for detecting method-not-found errors in SpEL expressions.
1 parent fea0b91 commit 8458cee

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

core/src/main/java/com/predic8/membrane/core/lang/spel/SpELExchangeExpression.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import static java.lang.Boolean.*;
3232
import static org.springframework.expression.spel.SpelCompilerMode.*;
33+
import static org.springframework.expression.spel.SpelMessage.METHOD_NOT_FOUND;
3334

3435
public class SpELExchangeExpression extends AbstractExchangeExpression {
3536

@@ -84,7 +85,7 @@ public <T> T evaluate(Exchange exchange, Flow flow, Class<T> type) {
8485
} catch (SpelEvaluationException see) {
8586
ExchangeExpressionException eee = new ExchangeExpressionException(expression, see);
8687
String msg ;
87-
if (see.getMessage().contains("EL1004E")) {
88+
if (see.getMessageCode() == METHOD_NOT_FOUND) {
8889
msg = "Method not found in expression '%s' use a SpEL function or one of Membrane's: %s".formatted(expression, SpELBuiltInFunctions.getBuiltInFunctionNames());
8990
} else if (see.getCause() instanceof ConverterNotFoundException cnfe) {
9091
msg = "Type converter not found for expression '%s' from '%s' to '%s'.".formatted(expression, cnfe.getSourceType(), cnfe.getTargetType());

0 commit comments

Comments
 (0)