From e0c08e64e8490504313bcf669b0da8e492ab6c4b Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Fri, 11 Jan 2019 11:33:29 +0100 Subject: [PATCH] DATACMNS-1466 - Fixed potential ArrayIndexOutOfBoundsException in DefaultPersistentPropertyPath. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduced explicit content checks in ….getLeafProperty() and ….getBaseProperty(). --- .../context/DefaultPersistentPropertyPath.java | 4 ++-- .../DefaultPersistentPropertyPathUnitTests.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java b/src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java index 13f320492..3fbdebac5 100644 --- a/src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java +++ b/src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java @@ -144,7 +144,7 @@ class DefaultPersistentPropertyPath

> 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

> implements */ @Nullable public P getBaseProperty() { - return properties.get(0); + return properties.isEmpty() ? null : properties.get(0); } /* diff --git a/src/test/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPathUnitTests.java b/src/test/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPathUnitTests.java index aa5570053..1ffc4a8d7 100755 --- a/src/test/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPathUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPathUnitTests.java @@ -138,4 +138,20 @@ public class DefaultPersistentPropertyPathUnitTests

"")).isNull(); } + + @Test // DATACMNS-1466 + public void returnsNullForLeafPropertyOnEmptyPath() { + + PersistentPropertyPath

path = new DefaultPersistentPropertyPath

(Collections.emptyList()); + + assertThat(path.getLeafProperty()).isNull(); + } + + @Test // DATACMNS-1466 + public void returnsNullForBasePropertyOnEmptyPath() { + + PersistentPropertyPath

path = new DefaultPersistentPropertyPath

(Collections.emptyList()); + + assertThat(path.getBaseProperty()).isNull(); + } }