Skip to content

Commit edcaee3

Browse files
committed
Consider @deprecated on field when determining property's deprecation
Fixes gh-17550
1 parent 4fd7b68 commit edcaee3

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ private void processSimpleTypes(String prefix, TypeElement element, ExecutableEl
277277
String sourceType = this.typeUtils.getQualifiedName(element);
278278
String description = this.typeUtils.getJavaDoc(field);
279279
Object defaultValue = fieldValues.get(name);
280-
boolean deprecated = isDeprecated(getter) || isDeprecated(setter) || isDeprecated(source);
280+
boolean deprecated = isDeprecated(getter) || isDeprecated(setter) || isDeprecated(field)
281+
|| isDeprecated(source);
281282
this.metadataCollector.add(ItemMetadata.newProperty(prefix, name, dataType, sourceType, null,
282283
description, defaultValue, deprecated ? getItemDeprecation(getter) : null));
283284
}

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import org.springframework.boot.configurationsample.method.MethodAndClassConfig;
7070
import org.springframework.boot.configurationsample.method.SimpleMethodConfig;
7171
import org.springframework.boot.configurationsample.simple.ClassWithNestedProperties;
72+
import org.springframework.boot.configurationsample.simple.DeprecatedFieldSingleProperty;
7273
import org.springframework.boot.configurationsample.simple.DeprecatedSingleProperty;
7374
import org.springframework.boot.configurationsample.simple.DescriptionProperties;
7475
import org.springframework.boot.configurationsample.simple.HierarchicalProperties;
@@ -224,6 +225,15 @@ public void singleDeprecatedProperty() {
224225
.withDeprecation("renamed", "singledeprecated.new-name"));
225226
}
226227

228+
@Test
229+
public void singleDeprecatedFieldProperty() {
230+
Class<?> type = DeprecatedFieldSingleProperty.class;
231+
ConfigurationMetadata metadata = compile(type);
232+
assertThat(metadata).has(Metadata.withGroup("singlefielddeprecated").fromSource(type));
233+
assertThat(metadata).has(Metadata.withProperty("singlefielddeprecated.name", String.class).fromSource(type)
234+
.withDeprecation(null, null));
235+
}
236+
227237
@Test
228238
public void deprecatedOnUnrelatedSetter() {
229239
Class<?> type = DeprecatedUnrelatedMethodPojo.class;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.configurationsample.simple;
18+
19+
import org.springframework.boot.configurationsample.ConfigurationProperties;
20+
21+
/**
22+
* Configuration properties with a single deprecated element.
23+
*
24+
* @author Andy Wilkinson
25+
*/
26+
@ConfigurationProperties("singlefielddeprecated")
27+
public class DeprecatedFieldSingleProperty {
28+
29+
@Deprecated
30+
private String name;
31+
32+
public String getName() {
33+
return this.name;
34+
}
35+
36+
public void setName(String name) {
37+
this.name = name;
38+
}
39+
40+
}

0 commit comments

Comments
 (0)