Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid ArrayIndexOutOfBoundsException from Indexer.java
When index==arrayLength, array index is also out of bound, SpelEvaluationException should also be thrown instead of ArrayIndexOutOfBoundsException.
- Loading branch information
1 parent
74897bc
commit 4e91cf8
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
spring-expression/src/test/java/org/springframework/expression/spel/ast/IndexerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.springframework.expression.spel.ast; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.expression.EvaluationException; | ||
import org.springframework.expression.spel.standard.SpelExpression; | ||
import org.springframework.expression.spel.standard.SpelExpressionParser; | ||
import org.springframework.expression.spel.support.SimpleEvaluationContext; | ||
import org.springframework.expression.spel.testresources.Inventor; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
||
/** | ||
* @author Joyce Zhan | ||
*/ | ||
public class IndexerTests { | ||
@Test | ||
public void testAccess() { | ||
SimpleEvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build(); | ||
SpelExpression expression = (SpelExpression) new SpelExpressionParser().parseExpression("stringArrayOfThreeItems[3]"); | ||
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> | ||
expression.getValue(context, new Inventor())); | ||
} | ||
} |