Browse Source

DATACMNS-1466 - Fixed potential ArrayIndexOutOfBoundsException in DefaultPersistentPropertyPath.

Introduced explicit content checks in ….getLeafProperty() and ….getBaseProperty().
pull/348/head
Oliver Drotbohm 7 years ago
parent
commit
4182dace3c
No known key found for this signature in database
GPG Key ID: 6E42B5787543F690
  1. 4
      src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java
  2. 16
      src/test/java/org/springframework/data/mapping/context/DefaultPersistenPropertyPathUnitTests.java

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

@ -145,7 +145,7 @@ class DefaultPersistentPropertyPath<T extends PersistentProperty<T>> implements @@ -145,7 +145,7 @@ class DefaultPersistentPropertyPath<T extends PersistentProperty<T>> implements
* @see org.springframework.data.mapping.context.PersistentPropertyPath#getLeafProperty()
*/
public T getLeafProperty() {
return properties.get(properties.size() - 1);
return properties.isEmpty() ? null : properties.get(properties.size() - 1);
}
/*
@ -153,7 +153,7 @@ class DefaultPersistentPropertyPath<T extends PersistentProperty<T>> implements @@ -153,7 +153,7 @@ class DefaultPersistentPropertyPath<T extends PersistentProperty<T>> implements
* @see org.springframework.data.mapping.context.PersistentPropertyPath#getBaseProperty()
*/
public T getBaseProperty() {
return properties.get(0);
return properties.isEmpty() ? null : properties.get(0);
}
/*

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

@ -21,6 +21,7 @@ import static org.mockito.Matchers.*; @@ -21,6 +21,7 @@ import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
@ -148,4 +149,19 @@ public class DefaultPersistenPropertyPathUnitTests<T extends PersistentProperty< @@ -148,4 +149,19 @@ public class DefaultPersistenPropertyPathUnitTests<T extends PersistentProperty<
assertThat(result, is(nullValue()));
}
@Test // DATACMNS-1466
public void returnsNullForLeafPropertyOnEmptyPath() {
PersistentPropertyPath<T> path = new DefaultPersistentPropertyPath<T>(Collections.<T> emptyList());
assertThat(path.getLeafProperty(), is(nullValue()));
}
@Test // DATACMNS-1466
public void returnsNullForBasePropertyOnEmptyPath() {
PersistentPropertyPath<T> path = new DefaultPersistentPropertyPath<T>(Collections.<T> emptyList());
assertThat(path.getBaseProperty(), is(nullValue()));
}
}

Loading…
Cancel
Save