Skip to content

Commit 2956b86

Browse files
committed
Avoid creating ConfigurationPropertyName just to get its Elements
See gh-15760
1 parent e2532e1 commit 2956b86

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -195,7 +195,7 @@ public ConfigurationPropertyName append(String elementValue) {
195195
if (elementValue == null) {
196196
return this;
197197
}
198-
Elements additionalElements = of(elementValue).elements;
198+
Elements additionalElements = elementsOf(elementValue);
199199
return new ConfigurationPropertyName(this.elements.append(additionalElements));
200200
}
201201

@@ -420,12 +420,21 @@ public static ConfigurationPropertyName of(CharSequence name) {
420420
* {@code returnNullIfInvalid} is {@code false}
421421
*/
422422
static ConfigurationPropertyName of(CharSequence name, boolean returnNullIfInvalid) {
423+
Elements elements = elementsOf(name, returnNullIfInvalid);
424+
return (elements != null) ? new ConfigurationPropertyName(elements) : null;
425+
}
426+
427+
private static Elements elementsOf(CharSequence name) {
428+
return elementsOf(name, false);
429+
}
430+
431+
private static Elements elementsOf(CharSequence name, boolean returnNullIfInvalid) {
423432
if (name == null) {
424433
Assert.isTrue(returnNullIfInvalid, "Name must not be null");
425434
return null;
426435
}
427436
if (name.length() == 0) {
428-
return EMPTY;
437+
return Elements.EMPTY;
429438
}
430439
if (name.charAt(0) == '.' || name.charAt(name.length() - 1) == '.') {
431440
if (returnNullIfInvalid) {
@@ -444,7 +453,7 @@ static ConfigurationPropertyName of(CharSequence name, boolean returnNullIfInval
444453
getInvalidChars(elements, i));
445454
}
446455
}
447-
return new ConfigurationPropertyName(elements);
456+
return elements;
448457
}
449458

450459
private static List<Character> getInvalidChars(Elements elements, int index) {

0 commit comments

Comments
 (0)