org.springframework.expression.spel.SpelEvaluationException: EL1072E:(pos 0): An exception occurred whilst evaluating a compiled expression

Spring JIRA | Christoph Strobl | 2 years ago
  1. 0

    Calling registered custom functions does not work once compiled SpEL expression is used. (tried with 4.1, 4.1.1 and 4.1.2 snapshot) {noformat} org.springframework.expression.spel.SpelEvaluationException: EL1072E:(pos 0): An exception occurred whilst evaluating a compiled expression at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:180) {noformat} The below tests passes once {{doFormat}} is registered as {{context.registerFunction("doFormat", String.class.getDeclaredMethod("format", String.class, Object[].class));}} but fails when using some custom class. {code:java} Test public void compiledExpressionShouldWorkWhenUsingCustomFunctionWithVarargs() throws NoSuchMethodException, SecurityException { SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, this .getClass().getClassLoader())); SpelExpression expression = parser.parseRaw("#doFormat([0], #arg)"); StandardEvaluationContext context = new StandardEvaluationContext(new Object[] { "hey %s" }); context.registerFunction("doFormat", DelegatingStringFormat.class.getDeclaredMethod("format", String.class, Object[].class)); context.setVariable("arg", "there"); expression.setEvaluationContext(context); assertThat(expression.getValue(String.class), is("hey there")); assertThat(expression.getValue(String.class), is("hey there")); // have to call it 3 time to fail assertThat(expression.getValue(String.class), is("hey there")); } static class DelegatingStringFormat { static String format(String s, Object... args) { return String.format(s, args); } } {code} The above will work once we change the method signature of {{DelegatingStringFormat.format}} to {{static String format(String s, Object[] args)}}. Another failing sample not using varargs: {code:java} @Test public void compiledExpressionShouldWorkWhenUsingCustomFunction() throws NoSuchMethodException, SecurityException { SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, this.getClass().getClassLoader())); SpelExpression expression = parser.parseRaw("#doCompare([0], #arg)"); StandardEvaluationContext context = new StandardEvaluationContext(new Object[] { "1" }); context.registerFunction("doCompare", SomeCompareMethod.class.getDeclaredMethod("compare", Object.class, Object.class)); context.setVariable("arg", "2"); expression.setEvaluationContext(context); assertThat(expression.getValue(Integer.class), is(-1)); assertThat(expression.getValue(Integer.class), is(-1)); // have to call it 3 time to fail assertThat(expression.getValue(Integer.class), is(-1)); } static class SomeCompareMethod { static int compare(Object o1, Object o2) { return new ComparableComparator().compare(o1, o2); } } {code}

    Spring JIRA | 2 years ago | Christoph Strobl
    org.springframework.expression.spel.SpelEvaluationException: EL1072E:(pos 0): An exception occurred whilst evaluating a compiled expression
  2. 0

    Calling registered custom functions does not work once compiled SpEL expression is used. (tried with 4.1, 4.1.1 and 4.1.2 snapshot) {noformat} org.springframework.expression.spel.SpelEvaluationException: EL1072E:(pos 0): An exception occurred whilst evaluating a compiled expression at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:180) {noformat} The below tests passes once {{doFormat}} is registered as {{context.registerFunction("doFormat", String.class.getDeclaredMethod("format", String.class, Object[].class));}} but fails when using some custom class. {code:java} Test public void compiledExpressionShouldWorkWhenUsingCustomFunctionWithVarargs() throws NoSuchMethodException, SecurityException { SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, this .getClass().getClassLoader())); SpelExpression expression = parser.parseRaw("#doFormat([0], #arg)"); StandardEvaluationContext context = new StandardEvaluationContext(new Object[] { "hey %s" }); context.registerFunction("doFormat", DelegatingStringFormat.class.getDeclaredMethod("format", String.class, Object[].class)); context.setVariable("arg", "there"); expression.setEvaluationContext(context); assertThat(expression.getValue(String.class), is("hey there")); assertThat(expression.getValue(String.class), is("hey there")); // have to call it 3 time to fail assertThat(expression.getValue(String.class), is("hey there")); } static class DelegatingStringFormat { static String format(String s, Object... args) { return String.format(s, args); } } {code} The above will work once we change the method signature of {{DelegatingStringFormat.format}} to {{static String format(String s, Object[] args)}}. Another failing sample not using varargs: {code:java} @Test public void compiledExpressionShouldWorkWhenUsingCustomFunction() throws NoSuchMethodException, SecurityException { SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, this.getClass().getClassLoader())); SpelExpression expression = parser.parseRaw("#doCompare([0], #arg)"); StandardEvaluationContext context = new StandardEvaluationContext(new Object[] { "1" }); context.registerFunction("doCompare", SomeCompareMethod.class.getDeclaredMethod("compare", Object.class, Object.class)); context.setVariable("arg", "2"); expression.setEvaluationContext(context); assertThat(expression.getValue(Integer.class), is(-1)); assertThat(expression.getValue(Integer.class), is(-1)); // have to call it 3 time to fail assertThat(expression.getValue(Integer.class), is(-1)); } static class SomeCompareMethod { static int compare(Object o1, Object o2) { return new ComparableComparator().compare(o1, o2); } } {code}

    Spring JIRA | 2 years ago | Christoph Strobl
    org.springframework.expression.spel.SpelEvaluationException: EL1072E:(pos 0): An exception occurred whilst evaluating a compiled expression
  3. 0

    Pass parameter to Spring soap interceptor

    Stack Overflow | 3 months ago | ViratKohli
    org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'headers' cannot be found on object of type 'org.spri ngframework.beans.factory.config.BeanExpressionContext' - maybe not public?
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Spring Expression Language and Spring Security 3: accessing bean reference in @PreAuthorize

    Stack Overflow | 6 years ago | Jonck van der Kogel
    org.springframework.expression.spel.SpelEvaluationException: EL1057E:(pos 1): No bean resolver registered in the context to resolve access to bean 'testBean'
  6. 0

    Reversed if condition

    GitHub | 12 months ago | evelan
    org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Property or field 'username' cannot be found on null

  1. musketyr 5 times, last 7 days ago
  2. tvrmsmith 1 times, last 1 week ago
  3. gehel 14 times, last 1 week ago
  4. serious2monkeys 1 times, last 1 month ago
  5. Pilleo 2 times, last 2 months ago
8 more registered users
49 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.springframework.expression.spel.SpelEvaluationException

    EL1072E:(pos 0): An exception occurred whilst evaluating a compiled expression

    at org.springframework.expression.spel.standard.SpelExpression.getValue()
  2. Spring Expression Language (SpEL)
    SpelExpression.getValue
    1. org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:180)
    1 frame