Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException in MethodBasedEvaluationContext [SPR-14554] #19122

spring-projects-issues opened this issue Aug 2, 2016 · 4 comments


Copy link

@spring-projects-issues spring-projects-issues commented Aug 2, 2016

Matthias Rühl opened SPR-14554 and commented

java.lang.ArrayIndexOutOfBoundsException: 2
at org.springframework.context.expression.MethodBasedEvaluationContext.lazyLoadArguments(
at org.springframework.context.expression.MethodBasedEvaluationContext.lookupVariable(
at org.springframework.cache.interceptor.CacheEvaluationContext.lookupVariable(
at org.springframework.expression.spel.ExpressionState.lookupVariable(
at org.springframework.expression.spel.ast.VariableReference.getValueInternal(
at org.springframework.expression.spel.ast.MethodReference.getArguments(
at org.springframework.expression.spel.ast.MethodReference.getValueInternal(
at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(
at org.springframework.expression.spel.standard.SpelExpression.getValue(
at org.springframework.cache.interceptor.CacheOperationExpressionEvaluator.key(
at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.generateKey(
at org.springframework.cache.interceptor.CacheAspectSupport.generateKey(
at org.springframework.cache.interceptor.CacheAspectSupport.findCachedItem(
at org.springframework.cache.interceptor.CacheAspectSupport.execute(
at org.springframework.cache.interceptor.CacheAspectSupport.execute(
at org.springframework.cache.interceptor.CacheInterceptor.invoke(
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(

This is my cacheable annotation:

@Cacheable(value = "dummyCache", key = "'getSomethingList_'.concat(#var1).concat(T(java.util.Arrays).deepHashCode(#var2))")
List<Something> getSomethingList(String var1, Integer... var2);

Affects: 4.2.7, 4.3.2

Issue Links:

  • #19022 MethodBasedEvaluationContext.lazyLoadArguments() execution fails for empty variable arguments call

Referenced from: commits 4543a28, 48980a2, fae503d

Backported to: 4.2.8

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 3, 2016

Stéphane Nicoll commented

Is that exception thrown for every call or with a specific set of arguments? If so provide them, a sample would be better to reduce the amount of time to spend to reproduce the issue.

Also, I would strongly recommend you to use a KeyGenerator for this via the keyGenerator argument on the annotation. This bug isn't critical, you have an easy way out that is better IMO than your current code.

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 3, 2016

Matthias Rühl commented

With the following arguments the error occurs:
var1 = "A"
var2 = [10,20,30]

Sounds good, I will take a look at the KeyGenerator feature :)

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 8, 2016

Juergen Hoeller commented

It seems that this is a side effect of the change made for #19022 in 4.3.2: While args may be shorter than parameterNames in an empty-vararg scenario there, it may also be longer in a multi-vararg scenario... So this seems like a regression in 4.3.2, fixing an index-out-of-bounds in one scenario at the expense of causing it in the other. In order to address both scenarios, some more sophisticated treatment will be necessary: possibly loop until parameterNames is at its last element, then explicitly specify null if there is no args entry anymore, pass in the args value as-is if there is exactly one element left, or extract the remaining args entries into a dedicated array and specify that as variable value.

Let's also backport the revised algorithm to 4.2.8, addressing both scenarios there as well.

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 9, 2016

Juergen Hoeller commented

Since I've been researching our general varargs handling in SpEL a bit, I guess I should take this issue right away...

The existing MethodBasedEvaluationContextTests do not expose varargs the SpEL way (i.e. in a flattened array), which is why they are not leading to the index-out-of-bounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants