Browse Source

DATACMNS-1466 - Fixed potential ArrayIndexOutOfBoundsException in DefaultPersistentPropertyPath.

Introduced explicit content checks in ….getLeafProperty() and ….getBaseProperty().
pull/351/head
Oliver Drotbohm 7 years ago
parent
commit
7f771570c3
  1. 4
      src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java
  2. 16
      src/test/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPathUnitTests.java

4
src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java

@ -144,7 +144,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements @@ -144,7 +144,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
*/
@Nullable
public P getLeafProperty() {
return properties.get(properties.size() - 1);
return properties.isEmpty() ? null : properties.get(properties.size() - 1);
}
/*
@ -153,7 +153,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements @@ -153,7 +153,7 @@ class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements
*/
@Nullable
public P getBaseProperty() {
return properties.get(0);
return properties.isEmpty() ? null : properties.get(0);
}
/*

16
src/test/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPathUnitTests.java

@ -138,4 +138,20 @@ public class DefaultPersistentPropertyPathUnitTests<P extends PersistentProperty @@ -138,4 +138,20 @@ public class DefaultPersistentPropertyPathUnitTests<P extends PersistentProperty
public void skipsMappedPropertyNameIfConverterReturnsEmptyStrings() {
assertThat(twoLegs.toDotPath(source -> "")).isNull();
}
@Test // DATACMNS-1466
public void returnsNullForLeafPropertyOnEmptyPath() {
PersistentPropertyPath<P> path = new DefaultPersistentPropertyPath<P>(Collections.emptyList());
assertThat(path.getLeafProperty()).isNull();
}
@Test // DATACMNS-1466
public void returnsNullForBasePropertyOnEmptyPath() {
PersistentPropertyPath<P> path = new DefaultPersistentPropertyPath<P>(Collections.emptyList());
assertThat(path.getBaseProperty()).isNull();
}
}

Loading…
Cancel
Save