Announcement Announcement Module
Collapse
No announcement yet.
Spel expression conflict with T() operator and Spel reserved keyword Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spel expression conflict with T() operator and Spel reserved keyword

    How can I use the T() operator to get a type reference of a class whose package structure contains a spel reserved keyword?

    Example: T(foo.ge.bar.Constants)
    In this case the subpackage ge is interpreted as the comparison operator greater or equal (>=).

    Is it a bug? Or is there a workaround for that?

    Here is the code example and the exception detail I'm getting:

    Code:
    package foo.ge.bar;
    
    import org.springframework.expression.Expression;
    import org.springframework.expression.ExpressionParser;
    import org.springframework.expression.spel.standard.SpelExpressionParser;
    
    public class Constants {
       public static final String HELLO = "world";
       public static void main(String[] args) {
          ExpressionParser parser = new SpelExpressionParser();
          Expression exp = parser.parseExpression("T(foo.ge.bar.Constants).HELLO");
          String world = (String) exp.getValue();
       }
    }
    Code:
    Exception in thread "main" org.springframework.expression.spel.SpelParseException: EL1043E:(pos 6): Unexpected token.  Expected 'identifier' but was 'ge(>=)'
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.raiseInternalException(InternalSpelExpressionParser.java:814)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatToken(InternalSpelExpressionParser.java:744)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatPossiblyQualifiedId(InternalSpelExpressionParser.java:593)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.maybeEatTypeReference(InternalSpelExpressionParser.java:498)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatStartNode(InternalSpelExpressionParser.java:452)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatPrimaryExpression(InternalSpelExpressionParser.java:300)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatUnaryExpression(InternalSpelExpressionParser.java:293)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatPowerExpression(InternalSpelExpressionParser.java:269)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatProductExpression(InternalSpelExpressionParser.java:250)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatSumExpression(InternalSpelExpressionParser.java:233)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatRelationalExpression(InternalSpelExpressionParser.java:195)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatLogicalAndExpression(InternalSpelExpressionParser.java:183)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatLogicalOrExpression(InternalSpelExpressionParser.java:171)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatExpression(InternalSpelExpressionParser.java:135)
    	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:116)
    	at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:56)
    	at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:1)
    	at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:66)
    	at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:56)
    	at foo.ge.bar.Constants.main(Constants.java:11)
Working...
X