Polish "Support @Value for record injection"

See gh-28774
This commit is contained in:
Sam Brannen
2023-02-28 13:06:18 +01:00
parent 7c9fc575ff
commit 00c2c1d2a1
2 changed files with 21 additions and 13 deletions

View File

@@ -1353,10 +1353,6 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @param bw the BeanWrapper with bean instance
*/
protected void populateBean(String beanName, RootBeanDefinition mbd, @Nullable BeanWrapper bw) {
// record has not set methods
if (mbd.getBeanClass().isRecord()) {
return;
}
if (bw == null) {
if (mbd.hasPropertyValues()) {
throw new BeanCreationException(
@@ -1368,6 +1364,17 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
}
if (bw.getWrappedClass().isRecord()) {
if (mbd.hasPropertyValues()) {
throw new BeanCreationException(
mbd.getResourceDescription(), beanName, "Cannot apply property values to a record");
}
else {
// Skip property population phase for records since they are immutable.
return;
}
}
// Give any InstantiationAwareBeanPostProcessors the opportunity to modify the
// state of the bean before properties are set. This can be used, for example,
// to support styles of field injection.