Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
1831f3be
Commit
1831f3be
authored
Jul 25, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix NPE when Collection contains unbound children
Fixes gh-13636
parent
6032b454
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
IndexedElementsBinder.java
...k/boot/context/properties/bind/IndexedElementsBinder.java
+4
-3
CollectionBinderTests.java
...k/boot/context/properties/bind/CollectionBinderTests.java
+23
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java
View file @
1831f3be
...
@@ -128,9 +128,10 @@ abstract class IndexedElementsBinder<T> extends AggregateBinder<T> {
...
@@ -128,9 +128,10 @@ abstract class IndexedElementsBinder<T> extends AggregateBinder<T> {
}
}
for
(
ConfigurationPropertyName
name
:
(
IterableConfigurationPropertySource
)
source
for
(
ConfigurationPropertyName
name
:
(
IterableConfigurationPropertySource
)
source
.
filter
(
root:
:
isAncestorOf
))
{
.
filter
(
root:
:
isAncestorOf
))
{
name
=
name
.
chop
(
root
.
getNumberOfElements
()
+
1
);
ConfigurationPropertyName
choppedName
=
name
if
(
name
.
isLastElementIndexed
())
{
.
chop
(
root
.
getNumberOfElements
()
+
1
);
String
key
=
name
.
getLastElement
(
Form
.
UNIFORM
);
if
(
choppedName
.
isLastElementIndexed
())
{
String
key
=
choppedName
.
getLastElement
(
Form
.
UNIFORM
);
ConfigurationProperty
value
=
source
.
getConfigurationProperty
(
name
);
ConfigurationProperty
value
=
source
.
getConfigurationProperty
(
name
);
children
.
add
(
key
,
value
);
children
.
add
(
key
,
value
);
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java
View file @
1831f3be
...
@@ -134,6 +134,29 @@ public class CollectionBinderTests {
...
@@ -134,6 +134,29 @@ public class CollectionBinderTests {
}
}
}
}
@Test
public
void
bindToNonScalarCollectionWhenNonSequentialShouldThrowException
()
{
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
source
.
put
(
"foo[0].value"
,
"1"
);
source
.
put
(
"foo[1].value"
,
"2"
);
source
.
put
(
"foo[4].value"
,
"4"
);
this
.
sources
.
add
(
source
);
try
{
Bindable
<
List
<
JavaBean
>>
target
=
Bindable
.
listOf
(
JavaBean
.
class
);
this
.
binder
.
bind
(
"foo"
,
target
);
fail
(
"No exception thrown"
);
}
catch
(
BindException
ex
)
{
ex
.
printStackTrace
();
Set
<
ConfigurationProperty
>
unbound
=
((
UnboundConfigurationPropertiesException
)
ex
.
getCause
()).
getUnboundProperties
();
assertThat
(
unbound
).
hasSize
(
1
);
ConfigurationProperty
property
=
unbound
.
iterator
().
next
();
assertThat
(
property
.
getName
().
toString
()).
isEqualTo
(
"foo[4].value"
);
assertThat
(
property
.
getValue
()).
isEqualTo
(
"4"
);
}
}
@Test
@Test
public
void
bindToCollectionWhenNonIterableShouldReturnPopulatedCollection
()
{
public
void
bindToCollectionWhenNonIterableShouldReturnPopulatedCollection
()
{
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment