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
e6409083
Commit
e6409083
authored
Jul 28, 2017
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Nested Map should not bind to null"
This reverts commit
54065677
.
parent
54065677
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
43 deletions
+9
-43
Binder.java
.../springframework/boot/context/properties/bind/Binder.java
+9
-8
BinderTests.java
...ngframework/boot/context/properties/bind/BinderTests.java
+0
-35
No files found.
spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java
View file @
e6409083
...
...
@@ -298,10 +298,11 @@ public class Binder {
}
BeanPropertyBinder
propertyBinder
=
(
propertyName
,
propertyTarget
)
->
bind
(
name
.
append
(
propertyName
),
propertyTarget
,
handler
,
context
);
if
(
context
.
isProcessingName
(
name
))
{
Class
<?>
type
=
target
.
getType
().
resolve
();
if
(
context
.
hasBoundBean
(
type
))
{
return
null
;
}
return
context
.
with
Name
(
nam
e
,
()
->
{
return
context
.
with
Bean
(
typ
e
,
()
->
{
Stream
<?>
boundBeans
=
BEAN_BINDERS
.
stream
()
.
map
((
b
)
->
b
.
bind
(
name
,
target
,
context
,
propertyBinder
));
return
boundBeans
.
filter
(
Objects:
:
nonNull
).
findFirst
().
orElse
(
null
);
...
...
@@ -352,7 +353,7 @@ public class Binder {
private
final
List
<
ConfigurationPropertySource
>
source
=
Arrays
.
asList
((
ConfigurationPropertySource
)
null
);
private
final
Deque
<
C
onfigurationPropertyName
>
name
s
=
new
ArrayDeque
<>();
private
final
Deque
<
C
lass
<?>>
bean
s
=
new
ArrayDeque
<>();
private
ConfigurationProperty
configurationProperty
;
...
...
@@ -384,13 +385,13 @@ public class Binder {
}
}
public
<
T
>
T
with
Name
(
ConfigurationPropertyName
name
,
Supplier
<
T
>
supplier
)
{
this
.
names
.
push
(
name
);
public
<
T
>
T
with
Bean
(
Class
<?>
bean
,
Supplier
<
T
>
supplier
)
{
this
.
beans
.
push
(
bean
);
try
{
return
withIncreasedDepth
(
supplier
);
}
finally
{
this
.
name
s
.
pop
();
this
.
bean
s
.
pop
();
}
}
...
...
@@ -420,8 +421,8 @@ public class Binder {
return
StreamSupport
.
stream
(
Binder
.
this
.
sources
.
spliterator
(),
false
);
}
public
boolean
isProcessingName
(
ConfigurationPropertyName
name
)
{
return
this
.
names
.
contains
(
name
);
public
boolean
hasBoundBean
(
Class
<?>
bean
)
{
return
this
.
beans
.
contains
(
bean
);
}
@Override
...
...
spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java
View file @
e6409083
...
...
@@ -19,9 +19,7 @@ package org.springframework.boot.context.properties.bind;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.assertj.core.matcher.AssertionMatcher
;
import
org.junit.Before
;
...
...
@@ -239,19 +237,6 @@ public class BinderTests {
this
.
binder
.
bind
(
"foo"
,
target
);
}
@Test
public
void
nestedMapsShouldNotBindToNull
()
throws
Exception
{
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
source
.
put
(
"foo.value"
,
"one"
);
source
.
put
(
"foo.foos.foo1.value"
,
"two"
);
source
.
put
(
"foo.foos.foo2.value"
,
"three"
);
this
.
sources
.
add
(
source
);
BindResult
<
Foo
>
foo
=
this
.
binder
.
bind
(
"foo"
,
Foo
.
class
);
assertThat
(
foo
.
get
().
getValue
()).
isNotNull
();
assertThat
(
foo
.
get
().
getFoos
().
get
(
"foo1"
).
getValue
()).
isEqualTo
(
"two"
);
assertThat
(
foo
.
get
().
getFoos
().
get
(
"foo2"
).
getValue
()).
isEqualTo
(
"three"
);
}
public
static
class
JavaBean
{
private
String
value
;
...
...
@@ -278,24 +263,4 @@ public class BinderTests {
}
static
class
Foo
{
private
String
value
;
private
Map
<
String
,
Foo
>
foos
=
new
LinkedHashMap
<>();
public
Map
<
String
,
Foo
>
getFoos
()
{
return
this
.
foos
;
}
public
String
getValue
()
{
return
this
.
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
}
}
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