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
9384e5c3
Commit
9384e5c3
authored
Mar 15, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix binding to bean with cloned arrays
Fixes gh-12478
parent
cb3da28b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
12 deletions
+51
-12
AggregateBinder.java
...amework/boot/context/properties/bind/AggregateBinder.java
+4
-4
ArrayBinder.java
...ngframework/boot/context/properties/bind/ArrayBinder.java
+2
-1
CollectionBinder.java
...mework/boot/context/properties/bind/CollectionBinder.java
+10
-4
MapBinder.java
...ringframework/boot/context/properties/bind/MapBinder.java
+9
-3
CollectionBinderTests.java
...k/boot/context/properties/bind/CollectionBinderTests.java
+26
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/AggregateBinder.java
View file @
9384e5c3
...
...
@@ -57,10 +57,10 @@ abstract class AggregateBinder<T> {
AggregateElementBinder
elementBinder
)
{
Object
result
=
bindAggregate
(
name
,
target
,
elementBinder
);
Supplier
<?>
value
=
target
.
getValue
();
if
(
result
==
null
||
value
==
null
||
value
.
get
()
==
null
)
{
if
(
result
==
null
||
value
==
null
)
{
return
result
;
}
return
merge
(
(
T
)
value
.
get
()
,
(
T
)
result
);
return
merge
(
value
,
(
T
)
result
);
}
/**
...
...
@@ -75,11 +75,11 @@ abstract class AggregateBinder<T> {
/**
* Merge any additional elements into the existing aggregate.
* @param existing the existing value
* @param existing the
supplier for the
existing value
* @param additional the additional elements to merge
* @return the merged result
*/
protected
abstract
T
merge
(
T
existing
,
T
additional
);
protected
abstract
T
merge
(
Supplier
<?>
existing
,
T
additional
);
/**
* Return the context being used by this binder.
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ArrayBinder.java
View file @
9384e5c3
...
...
@@ -19,6 +19,7 @@ package org.springframework.boot.context.properties.bind;
import
java.lang.reflect.Array
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.function.Supplier
;
import
org.springframework.boot.context.properties.bind.Binder.Context
;
import
org.springframework.boot.context.properties.source.ConfigurationPropertyName
;
...
...
@@ -55,7 +56,7 @@ class ArrayBinder extends IndexedElementsBinder<Object> {
}
@Override
protected
Object
merge
(
Object
existing
,
Object
additional
)
{
protected
Object
merge
(
Supplier
<?>
existing
,
Object
additional
)
{
return
additional
;
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/CollectionBinder.java
View file @
9384e5c3
...
...
@@ -18,6 +18,7 @@ package org.springframework.boot.context.properties.bind;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.function.Supplier
;
import
org.springframework.boot.context.properties.bind.Binder.Context
;
import
org.springframework.boot.context.properties.source.ConfigurationPropertyName
;
...
...
@@ -54,12 +55,17 @@ class CollectionBinder extends IndexedElementsBinder<Collection<Object>> {
}
@Override
protected
Collection
<
Object
>
merge
(
Collection
<
Object
>
existing
,
@SuppressWarnings
(
"unchecked"
)
protected
Collection
<
Object
>
merge
(
Supplier
<?>
existing
,
Collection
<
Object
>
additional
)
{
Collection
<
Object
>
existingCollection
=
(
Collection
<
Object
>)
existing
.
get
();
if
(
existingCollection
==
null
)
{
return
additional
;
}
try
{
existing
.
clear
();
existing
.
addAll
(
additional
);
return
existing
;
existing
Collection
.
clear
();
existing
Collection
.
addAll
(
additional
);
return
existing
Collection
;
}
catch
(
UnsupportedOperationException
ex
)
{
return
createNewCollection
(
additional
);
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java
View file @
9384e5c3
...
...
@@ -19,6 +19,7 @@ package org.springframework.boot.context.properties.bind;
import
java.util.Collection
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.function.Supplier
;
import
org.springframework.boot.context.properties.bind.Binder.Context
;
import
org.springframework.boot.context.properties.source.ConfigurationProperty
;
...
...
@@ -82,10 +83,15 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
}
@Override
protected
Map
<
Object
,
Object
>
merge
(
Map
<
Object
,
Object
>
existing
,
@SuppressWarnings
(
"unchecked"
)
protected
Map
<
Object
,
Object
>
merge
(
Supplier
<?>
existing
,
Map
<
Object
,
Object
>
additional
)
{
existing
.
putAll
(
additional
);
return
existing
;
Map
<
Object
,
Object
>
existingMap
=
(
Map
<
Object
,
Object
>)
existing
.
get
();
if
(
existingMap
==
null
)
{
return
additional
;
}
existingMap
.
putAll
(
additional
);
return
existingMap
;
}
private
class
EntryBinder
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java
View file @
9384e5c3
...
...
@@ -384,6 +384,17 @@ public class CollectionBinderTests {
this
.
binder
.
bind
(
"foo"
,
target
);
}
@Test
public
void
bindToBeanWithClonedArray
()
{
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
source
.
put
(
"foo.bar[0]"
,
"hello"
);
this
.
sources
.
add
(
source
);
Bindable
<
ClonedArrayBean
>
target
=
Bindable
.
of
(
ClonedArrayBean
.
class
);
ClonedArrayBean
bean
=
this
.
binder
.
bind
(
"foo"
,
target
).
get
();
assertThat
(
bean
.
getBar
()).
contains
(
"hello"
);
}
public
static
class
ExampleCollectionBean
{
private
List
<
String
>
items
=
new
ArrayList
<>();
...
...
@@ -457,4 +468,19 @@ public class CollectionBinderTests {
}
}
public
static
class
ClonedArrayBean
{
private
String
[]
bar
;
public
String
[]
getBar
()
{
return
this
.
bar
.
clone
();
}
public
void
setBar
(
String
[]
bar
)
{
this
.
bar
=
bar
;
}
}
}
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