Fix detection of property setter
Previously, the meta-data annotation processor was taking the first setter that match the property name it has to handle. Contrary to getters that are enforced by a return type (no argument), multiple setter candidates may exist. If a property's type got narrowed over time, the original setter may have been marked as Deprecated. As the annotation processor takes the first setter that matches based on the name only, it may pick up the deprecated one and therefore mark the property as being (wrongly) deprecatede in the meta-data. It turns out that checking for the actual type of the setter parameter brought a side effect: some primitive properties may use the primitive or the Wrapper counter part. This commit not only look at the proper setter based on the type but also fallback on the wrapper (or) primitive if necessary. Closes gh-4338pull/4359/head
parent
5ed7156061
commit
0b326035b0
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2015 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.configurationsample.specific;
|
||||||
|
|
||||||
|
import org.springframework.boot.configurationsample.ConfigurationProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demonstrate the use of boxing/unboxing. Even if the type does not
|
||||||
|
* strictly match, it should still be detected.
|
||||||
|
*
|
||||||
|
* @author Stephane Nicoll
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties("boxing")
|
||||||
|
public class BoxingPojo {
|
||||||
|
|
||||||
|
private boolean flag;
|
||||||
|
|
||||||
|
private Integer counter;
|
||||||
|
|
||||||
|
public boolean isFlag() {
|
||||||
|
return this.flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setter use Boolean
|
||||||
|
public void setFlag(Boolean flag) {
|
||||||
|
this.flag = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCounter() {
|
||||||
|
return this.counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setter use int
|
||||||
|
public void setCounter(int counter) {
|
||||||
|
this.counter = counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2015 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.configurationsample.specific;
|
||||||
|
|
||||||
|
import org.springframework.boot.configurationsample.ConfigurationProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demonstrate that an unrelated setter is not taken into account
|
||||||
|
* to detect the deprecated flag.
|
||||||
|
*
|
||||||
|
* @author Stephane Nicoll
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties("not.deprecated")
|
||||||
|
public class DeprecatedUnrelatedMethodPojo {
|
||||||
|
|
||||||
|
private Integer counter;
|
||||||
|
|
||||||
|
private boolean flag;
|
||||||
|
|
||||||
|
public Integer getCounter() {
|
||||||
|
return this.counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCounter(Integer counter) {
|
||||||
|
this.counter = counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void setCounter(String counterAsString) {
|
||||||
|
this.counter = Integer.valueOf(counterAsString);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFlag() {
|
||||||
|
return this.flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFlag(boolean flag) {
|
||||||
|
this.flag = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void setFlag(Boolean flag) {
|
||||||
|
this.flag = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue