Skip to content

Commit 42ff01b

Browse files
committed
Merge branch '5.2.x'
2 parents 5f9e951 + 914425e commit 42ff01b

File tree

17 files changed

+269
-327
lines changed

17 files changed

+269
-327
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,16 +432,14 @@ public enum ResolutionMethod {
432432
/**
433433
* {@link Constructor} that supports filtering of unsupported types.
434434
* <p>If an unsupported type is encountered in a YAML document, an
435-
* {@link IllegalStateException} will be thrown from {@link #getClassForName(String)}.
436-
* @since 5.1.16
435+
* {@link IllegalStateException} will be thrown from {@link #getClassForName}.
437436
*/
438437
private class FilteringConstructor extends Constructor {
439438

440439
FilteringConstructor(LoaderOptions loaderOptions) {
441440
super(loaderOptions);
442441
}
443442

444-
445443
@Override
446444
protected Class<?> getClassForName(String name) throws ClassNotFoundException {
447445
Assert.state(YamlProcessor.this.supportedTypes.contains(name),

spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -79,6 +79,7 @@
7979
import org.springframework.core.io.support.ResourcePatternResolver;
8080
import org.springframework.lang.Nullable;
8181
import org.springframework.util.Assert;
82+
import org.springframework.util.CollectionUtils;
8283
import org.springframework.util.ObjectUtils;
8384
import org.springframework.util.ReflectionUtils;
8485

@@ -836,7 +837,7 @@ protected void registerListeners() {
836837
// Publish early application events now that we finally have a multicaster...
837838
Set<ApplicationEvent> earlyEventsToProcess = this.earlyApplicationEvents;
838839
this.earlyApplicationEvents = null;
839-
if (earlyEventsToProcess != null) {
840+
if (!CollectionUtils.isEmpty(earlyEventsToProcess)) {
840841
for (ApplicationEvent earlyEvent : earlyEventsToProcess) {
841842
getApplicationEventMulticaster().multicastEvent(earlyEvent);
842843
}

spring-core/src/main/java/org/springframework/core/env/AbstractPropertyResolver.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -223,6 +223,9 @@ public String resolveRequiredPlaceholders(String text) throws IllegalArgumentExc
223223
* @see #setIgnoreUnresolvableNestedPlaceholders
224224
*/
225225
protected String resolveNestedPlaceholders(String value) {
226+
if (value.isEmpty()) {
227+
return value;
228+
}
226229
return (this.ignoreUnresolvableNestedPlaceholders ?
227230
resolvePlaceholders(value) : resolveRequiredPlaceholders(value));
228231
}

spring-core/src/main/java/org/springframework/core/env/EnumerablePropertySource.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -44,10 +44,20 @@
4444
*/
4545
public abstract class EnumerablePropertySource<T> extends PropertySource<T> {
4646

47+
/**
48+
* Create a new {@code EnumerablePropertySource} with the given name and source object.
49+
* @param name the associated name
50+
* @param source the source object
51+
*/
4752
public EnumerablePropertySource(String name, T source) {
4853
super(name, source);
4954
}
5055

56+
/**
57+
* Create a new {@code EnumerablePropertySource} with the given name and with a new
58+
* {@code Object} instance as the underlying source.
59+
* @param name the associated name
60+
*/
5161
protected EnumerablePropertySource(String name) {
5262
super(name);
5363
}

spring-core/src/main/java/org/springframework/core/env/MapPropertySource.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -23,6 +23,8 @@
2323

2424
/**
2525
* {@link PropertySource} that reads keys and values from a {@code Map} object.
26+
* The underlying map should not contain any {@code null} values in order to
27+
* comply with {@link #getProperty} and {@link #containsProperty} semantics.
2628
*
2729
* @author Chris Beams
2830
* @author Juergen Hoeller
@@ -31,6 +33,12 @@
3133
*/
3234
public class MapPropertySource extends EnumerablePropertySource<Map<String, Object>> {
3335

36+
/**
37+
* Create a new {@code MapPropertySource} with the given name and {@code Map}.
38+
* @param name the associated name
39+
* @param source the Map source (without {@code null} values in order to get
40+
* consistent {@link #getProperty} and {@link #containsProperty} behavior)
41+
*/
3442
public MapPropertySource(String name, Map<String, Object> source) {
3543
super(name, source);
3644
}

spring-core/src/main/java/org/springframework/core/env/PropertyResolver.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -98,7 +98,6 @@ public interface PropertyResolver {
9898
* @return the resolved String (never {@code null})
9999
* @throws IllegalArgumentException if given text is {@code null}
100100
* @see #resolveRequiredPlaceholders
101-
* @see org.springframework.util.SystemPropertyUtils#resolvePlaceholders(String)
102101
*/
103102
String resolvePlaceholders(String text);
104103

@@ -109,7 +108,6 @@ public interface PropertyResolver {
109108
* @return the resolved String (never {@code null})
110109
* @throws IllegalArgumentException if given text is {@code null}
111110
* or if any placeholders are unresolvable
112-
* @see org.springframework.util.SystemPropertyUtils#resolvePlaceholders(String, boolean)
113111
*/
114112
String resolveRequiredPlaceholders(String text) throws IllegalArgumentException;
115113

spring-core/src/main/java/org/springframework/core/env/PropertySource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -68,6 +68,8 @@ public abstract class PropertySource<T> {
6868

6969
/**
7070
* Create a new {@code PropertySource} with the given name and source object.
71+
* @param name the associated name
72+
* @param source the source object
7173
*/
7274
public PropertySource(String name, T source) {
7375
Assert.hasText(name, "Property source name must contain at least one character");

spring-core/src/main/java/org/springframework/util/CollectionUtils.java

Lines changed: 14 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -16,15 +16,13 @@
1616

1717
package org.springframework.util;
1818

19-
import java.io.Serializable;
2019
import java.util.ArrayList;
2120
import java.util.Arrays;
2221
import java.util.Collection;
2322
import java.util.Collections;
2423
import java.util.Enumeration;
2524
import java.util.Iterator;
2625
import java.util.LinkedHashMap;
27-
import java.util.LinkedList;
2826
import java.util.List;
2927
import java.util.Map;
3028
import java.util.Properties;
@@ -412,25 +410,28 @@ public static <E> Iterator<E> toIterator(@Nullable Enumeration<E> enumeration) {
412410

413411
/**
414412
* Adapt a {@code Map<K, List<V>>} to an {@code MultiValueMap<K, V>}.
415-
* @param map the original map
416-
* @return the multi-value map
413+
* @param targetMap the original map
414+
* @return the adapted multi-value map (wrapping the original map)
417415
* @since 3.1
418416
*/
419-
public static <K, V> MultiValueMap<K, V> toMultiValueMap(Map<K, List<V>> map) {
420-
return new MultiValueMapAdapter<>(map);
417+
public static <K, V> MultiValueMap<K, V> toMultiValueMap(Map<K, List<V>> targetMap) {
418+
Assert.notNull(targetMap, "'targetMap' must not be null");
419+
return new MultiValueMapAdapter<>(targetMap);
421420
}
422421

423422
/**
424423
* Return an unmodifiable view of the specified multi-value map.
425-
* @param map the map for which an unmodifiable view is to be returned.
426-
* @return an unmodifiable view of the specified multi-value map.
424+
* @param targetMap the map for which an unmodifiable view is to be returned.
425+
* @return an unmodifiable view of the specified multi-value map
427426
* @since 3.1
428427
*/
429428
@SuppressWarnings("unchecked")
430-
public static <K, V> MultiValueMap<K, V> unmodifiableMultiValueMap(MultiValueMap<? extends K, ? extends V> map) {
431-
Assert.notNull(map, "'map' must not be null");
432-
Map<K, List<V>> result = new LinkedHashMap<>(map.size());
433-
map.forEach((key, value) -> {
429+
public static <K, V> MultiValueMap<K, V> unmodifiableMultiValueMap(
430+
MultiValueMap<? extends K, ? extends V> targetMap) {
431+
432+
Assert.notNull(targetMap, "'targetMap' must not be null");
433+
Map<K, List<V>> result = new LinkedHashMap<>(targetMap.size());
434+
targetMap.forEach((key, value) -> {
434435
List<? extends V> values = Collections.unmodifiableList(value);
435436
result.put(key, (List<V>) values);
436437
});
@@ -467,141 +468,4 @@ public void remove() throws UnsupportedOperationException {
467468
}
468469

469470

470-
/**
471-
* Adapts a Map to the MultiValueMap contract.
472-
*/
473-
@SuppressWarnings("serial")
474-
private static class MultiValueMapAdapter<K, V> implements MultiValueMap<K, V>, Serializable {
475-
476-
private final Map<K, List<V>> map;
477-
478-
public MultiValueMapAdapter(Map<K, List<V>> map) {
479-
Assert.notNull(map, "'map' must not be null");
480-
this.map = map;
481-
}
482-
483-
@Override
484-
@Nullable
485-
public V getFirst(K key) {
486-
List<V> values = this.map.get(key);
487-
return (values != null ? values.get(0) : null);
488-
}
489-
490-
@Override
491-
public void add(K key, @Nullable V value) {
492-
List<V> values = this.map.computeIfAbsent(key, k -> new LinkedList<>());
493-
values.add(value);
494-
}
495-
496-
@Override
497-
public void addAll(K key, List<? extends V> values) {
498-
List<V> currentValues = this.map.computeIfAbsent(key, k -> new LinkedList<>());
499-
currentValues.addAll(values);
500-
}
501-
502-
@Override
503-
public void addAll(MultiValueMap<K, V> values) {
504-
for (Entry<K, List<V>> entry : values.entrySet()) {
505-
addAll(entry.getKey(), entry.getValue());
506-
}
507-
}
508-
509-
@Override
510-
public void set(K key, @Nullable V value) {
511-
List<V> values = new LinkedList<>();
512-
values.add(value);
513-
this.map.put(key, values);
514-
}
515-
516-
@Override
517-
public void setAll(Map<K, V> values) {
518-
values.forEach(this::set);
519-
}
520-
521-
@Override
522-
public Map<K, V> toSingleValueMap() {
523-
LinkedHashMap<K, V> singleValueMap = new LinkedHashMap<>(this.map.size());
524-
this.map.forEach((key, value) -> singleValueMap.put(key, value.get(0)));
525-
return singleValueMap;
526-
}
527-
528-
@Override
529-
public int size() {
530-
return this.map.size();
531-
}
532-
533-
@Override
534-
public boolean isEmpty() {
535-
return this.map.isEmpty();
536-
}
537-
538-
@Override
539-
public boolean containsKey(Object key) {
540-
return this.map.containsKey(key);
541-
}
542-
543-
@Override
544-
public boolean containsValue(Object value) {
545-
return this.map.containsValue(value);
546-
}
547-
548-
@Override
549-
public List<V> get(Object key) {
550-
return this.map.get(key);
551-
}
552-
553-
@Override
554-
public List<V> put(K key, List<V> value) {
555-
return this.map.put(key, value);
556-
}
557-
558-
@Override
559-
public List<V> remove(Object key) {
560-
return this.map.remove(key);
561-
}
562-
563-
@Override
564-
public void putAll(Map<? extends K, ? extends List<V>> map) {
565-
this.map.putAll(map);
566-
}
567-
568-
@Override
569-
public void clear() {
570-
this.map.clear();
571-
}
572-
573-
@Override
574-
public Set<K> keySet() {
575-
return this.map.keySet();
576-
}
577-
578-
@Override
579-
public Collection<List<V>> values() {
580-
return this.map.values();
581-
}
582-
583-
@Override
584-
public Set<Entry<K, List<V>>> entrySet() {
585-
return this.map.entrySet();
586-
}
587-
588-
@Override
589-
public boolean equals(@Nullable Object other) {
590-
if (this == other) {
591-
return true;
592-
}
593-
return this.map.equals(other);
594-
}
595-
596-
@Override
597-
public int hashCode() {
598-
return this.map.hashCode();
599-
}
600-
601-
@Override
602-
public String toString() {
603-
return this.map.toString();
604-
}
605-
}
606-
607471
}

spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -273,8 +273,8 @@ public LinkedCaseInsensitiveMap<V> clone() {
273273
}
274274

275275
@Override
276-
public boolean equals(@Nullable Object obj) {
277-
return this.targetMap.equals(obj);
276+
public boolean equals(@Nullable Object other) {
277+
return (this == other || this.targetMap.equals(other));
278278
}
279279

280280
@Override

0 commit comments

Comments
 (0)