Merge branch '6.1.x'
This commit is contained in:
commit
f3ab3905b8
|
|
@ -810,6 +810,8 @@ public class Indexer extends SpelNodeImpl {
|
||||||
throw new SpelEvaluationException(getStartPosition(), ex,
|
throw new SpelEvaluationException(getStartPosition(), ex,
|
||||||
SpelMessage.EXCEPTION_DURING_PROPERTY_WRITE, this.name, ex.getMessage());
|
SpelMessage.EXCEPTION_DURING_PROPERTY_WRITE, this.name, ex.getMessage());
|
||||||
}
|
}
|
||||||
|
throw new SpelEvaluationException(getStartPosition(),
|
||||||
|
SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, this.targetObjectTypeDescriptor.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.assertj.core.api.ThrowableTypeAssert;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
|
|
@ -83,11 +84,11 @@ class PropertyAccessTests extends AbstractExpressionTests {
|
||||||
void accessingOnNullObject() {
|
void accessingOnNullObject() {
|
||||||
SpelExpression expr = (SpelExpression) parser.parseExpression("madeup");
|
SpelExpression expr = (SpelExpression) parser.parseExpression("madeup");
|
||||||
EvaluationContext context = new StandardEvaluationContext(null);
|
EvaluationContext context = new StandardEvaluationContext(null);
|
||||||
assertThatExceptionOfType(SpelEvaluationException.class)
|
assertThatSpelEvaluationException()
|
||||||
.isThrownBy(() -> expr.getValue(context))
|
.isThrownBy(() -> expr.getValue(context))
|
||||||
.extracting(SpelEvaluationException::getMessageCode).isEqualTo(SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL);
|
.extracting(SpelEvaluationException::getMessageCode).isEqualTo(SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL);
|
||||||
assertThat(expr.isWritable(context)).isFalse();
|
assertThat(expr.isWritable(context)).isFalse();
|
||||||
assertThatExceptionOfType(SpelEvaluationException.class)
|
assertThatSpelEvaluationException()
|
||||||
.isThrownBy(() -> expr.setValue(context, "abc"))
|
.isThrownBy(() -> expr.setValue(context, "abc"))
|
||||||
.extracting(SpelEvaluationException::getMessageCode).isEqualTo(SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
|
.extracting(SpelEvaluationException::getMessageCode).isEqualTo(SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
|
||||||
}
|
}
|
||||||
|
|
@ -117,8 +118,7 @@ class PropertyAccessTests extends AbstractExpressionTests {
|
||||||
assertThat((int) i).isEqualTo(99);
|
assertThat((int) i).isEqualTo(99);
|
||||||
|
|
||||||
// Cannot set it to a string value
|
// Cannot set it to a string value
|
||||||
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() ->
|
assertThatSpelEvaluationException().isThrownBy(() -> flibbleexpr.setValue(ctx, "not allowed"));
|
||||||
flibbleexpr.setValue(ctx, "not allowed"));
|
|
||||||
// message will be: EL1063E:(pos 20): A problem occurred whilst attempting to set the property
|
// message will be: EL1063E:(pos 20): A problem occurred whilst attempting to set the property
|
||||||
// 'flibbles': 'Cannot set flibbles to an object of type 'class java.lang.String''
|
// 'flibbles': 'Cannot set flibbles to an object of type 'class java.lang.String''
|
||||||
// System.out.println(e.getMessage());
|
// System.out.println(e.getMessage());
|
||||||
|
|
@ -173,8 +173,7 @@ class PropertyAccessTests extends AbstractExpressionTests {
|
||||||
@Test
|
@Test
|
||||||
void noGetClassAccess() {
|
void noGetClassAccess() {
|
||||||
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
|
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
|
||||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
assertThatSpelEvaluationException().isThrownBy(() -> parser.parseExpression("'a'.class.name").getValue(context));
|
||||||
parser.parseExpression("'a'.class.name").getValue(context));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -187,8 +186,13 @@ class PropertyAccessTests extends AbstractExpressionTests {
|
||||||
target.setName("p2");
|
target.setName("p2");
|
||||||
assertThat(expr.getValue(context, target)).isEqualTo("p2");
|
assertThat(expr.getValue(context, target)).isEqualTo("p2");
|
||||||
|
|
||||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
assertThatSpelEvaluationException()
|
||||||
parser.parseExpression("name='p3'").getValue(context, target));
|
.isThrownBy(() -> parser.parseExpression("name='p3'").getValue(context, target))
|
||||||
|
.extracting(SpelEvaluationException::getMessageCode).isEqualTo(SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE);
|
||||||
|
|
||||||
|
assertThatSpelEvaluationException()
|
||||||
|
.isThrownBy(() -> parser.parseExpression("['name']='p4'").getValue(context, target))
|
||||||
|
.extracting(SpelEvaluationException::getMessageCode).isEqualTo(SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -201,8 +205,9 @@ class PropertyAccessTests extends AbstractExpressionTests {
|
||||||
RecordPerson target2 = new RecordPerson("p2");
|
RecordPerson target2 = new RecordPerson("p2");
|
||||||
assertThat(expr.getValue(context, target2)).isEqualTo("p2");
|
assertThat(expr.getValue(context, target2)).isEqualTo("p2");
|
||||||
|
|
||||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
assertThatSpelEvaluationException()
|
||||||
parser.parseExpression("name='p3'").getValue(context, target2));
|
.isThrownBy(() -> parser.parseExpression("name='p3'").getValue(context, target2))
|
||||||
|
.extracting(SpelEvaluationException::getMessageCode).isEqualTo(SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -248,7 +253,7 @@ class PropertyAccessTests extends AbstractExpressionTests {
|
||||||
void propertyAccessWithoutMethodResolver() {
|
void propertyAccessWithoutMethodResolver() {
|
||||||
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
|
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
|
||||||
Person target = new Person("p1");
|
Person target = new Person("p1");
|
||||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
assertThatSpelEvaluationException().isThrownBy(() ->
|
||||||
parser.parseExpression("name.substring(1)").getValue(context, target));
|
parser.parseExpression("name.substring(1)").getValue(context, target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,12 +279,17 @@ class PropertyAccessTests extends AbstractExpressionTests {
|
||||||
void propertyAccessWithArrayIndexOutOfBounds() {
|
void propertyAccessWithArrayIndexOutOfBounds() {
|
||||||
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
|
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
|
||||||
Expression expression = parser.parseExpression("stringArrayOfThreeItems[3]");
|
Expression expression = parser.parseExpression("stringArrayOfThreeItems[3]");
|
||||||
assertThatExceptionOfType(SpelEvaluationException.class)
|
assertThatSpelEvaluationException()
|
||||||
.isThrownBy(() -> expression.getValue(context, new Inventor()))
|
.isThrownBy(() -> expression.getValue(context, new Inventor()))
|
||||||
.extracting(SpelEvaluationException::getMessageCode).isEqualTo(SpelMessage.ARRAY_INDEX_OUT_OF_BOUNDS);
|
.extracting(SpelEvaluationException::getMessageCode).isEqualTo(SpelMessage.ARRAY_INDEX_OUT_OF_BOUNDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ThrowableTypeAssert<SpelEvaluationException> assertThatSpelEvaluationException() {
|
||||||
|
return assertThatExceptionOfType(SpelEvaluationException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// This can resolve the property 'flibbles' on any String (very useful...)
|
// This can resolve the property 'flibbles' on any String (very useful...)
|
||||||
private static class StringyPropertyAccessor implements PropertyAccessor {
|
private static class StringyPropertyAccessor implements PropertyAccessor {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue