File tree Expand file tree Collapse file tree 3 files changed +34
-6
lines changed 
main/java/org/springframework/beans/factory/config 
test/java/org/springframework/beans/factory/config Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -293,10 +293,14 @@ else if (value instanceof Collection) {
293293				// Need a compound key 
294294				@ SuppressWarnings ("unchecked" )
295295				Collection <Object > collection  = (Collection <Object >) value ;
296- 				int  count  = 0 ;
297- 				for  (Object  object  : collection ) {
298- 					buildFlattenedMap (result ,
299- 							Collections .singletonMap ("["  + (count ++) + "]" , object ), key );
296+ 				if  (collection .isEmpty ()) {
297+ 					result .put (key , "" );
298+ 				} else  {
299+ 					int  count  = 0 ;
300+ 					for  (Object  object  : collection ) {
301+ 						buildFlattenedMap (result , Collections .singletonMap (
302+ 								"["  + (count ++) + "]" , object ), key );
303+ 					}
300304				}
301305			}
302306			else  {
Original file line number Diff line number Diff line change 11/* 
2-  * Copyright 2002-2017  the original author or authors. 
2+  * Copyright 2002-2018  the original author or authors. 
33 * 
44 * Licensed under the Apache License, Version 2.0 (the "License"); 
55 * you may not use this file except in compliance with the License. 
1919import  java .io .IOException ;
2020import  java .io .InputStream ;
2121import  java .util .LinkedHashMap ;
22+ import  java .util .List ;
2223import  java .util .Map ;
2324
2425import  org .junit .Test ;
@@ -116,6 +117,20 @@ public void testMapWithIntegerValue() throws Exception {
116117		assertEquals (Integer .valueOf (3 ), sub .get ("key1.key2" ));
117118	}
118119
120+ 	@ Test 
121+ 	public  void  mapWithEmptyArrayValue () {
122+ 		this .factory .setResources (new  ByteArrayResource ("a: alpha\n test: []" .getBytes ()));
123+ 		assertTrue (this .factory .getObject ().containsKey ("test" ));
124+ 		assertEquals (((List <?>)this .factory .getObject ().get ("test" )).size (), 0 );
125+ 	}
126+ 
127+ 	@ Test 
128+ 	public  void  mapWithEmptyValue () {
129+ 		this .factory .setResources (new  ByteArrayResource ("a: alpha\n test:" .getBytes ()));
130+ 		assertTrue (this .factory .getObject ().containsKey ("test" ));
131+ 		assertNull (this .factory .getObject ().get ("test" ));
132+ 	}
133+ 
119134	@ Test 
120135	public  void  testDuplicateKey () throws  Exception  {
121136		this .factory .setResources (new  ByteArrayResource ("mymap:\n   foo: bar\n mymap:\n   bar: foo" .getBytes ()));
Original file line number Diff line number Diff line change 11/* 
2-  * Copyright 2002-2017  the original author or authors. 
2+  * Copyright 2002-2018  the original author or authors. 
33 * 
44 * Licensed under the Apache License, Version 2.0 (the "License"); 
55 * you may not use this file except in compliance with the License. 
@@ -207,6 +207,15 @@ public void testLoadNull() throws Exception {
207207		assertThat (properties .getProperty ("spam" ), equalTo ("" ));
208208	}
209209
210+ 	@ Test 
211+ 	public  void  testLoadEmptyArrayValue () {
212+ 		YamlPropertiesFactoryBean  factory  = new  YamlPropertiesFactoryBean ();
213+ 		factory .setResources (new  ByteArrayResource ("a: alpha\n test: []" .getBytes ()));
214+ 		Properties  properties  = factory .getObject ();
215+ 		assertThat (properties .getProperty ("a" ), equalTo ("alpha" ));
216+ 		assertThat (properties .getProperty ("test" ), equalTo ("" ));
217+ 	}
218+ 
210219	@ Test 
211220	public  void  testLoadArrayOfString () throws  Exception  {
212221		YamlPropertiesFactoryBean  factory  = new  YamlPropertiesFactoryBean ();
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments