Browse Source

Make inner classes static when feasible (on main)

A static nested class does not keep an implicit reference to its
enclosing instance.

This prevents a common cause of memory leaks and uses less memory per
instance of the class.

Closes gh-28433
pull/28448/head
evgeny.bovykin 4 years ago committed by Sam Brannen
parent
commit
7cb6ac0a02
  1. 2
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
  2. 12
      spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGenerator.java
  3. 2
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

2
spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

@ -654,7 +654,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA @@ -654,7 +654,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
/**
* Base class representing injection information.
*/
private abstract class AutowiredElement extends InjectionMetadata.InjectedElement {
private abstract static class AutowiredElement extends InjectionMetadata.InjectedElement {
protected final boolean required;

12
spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGenerator.java

@ -119,7 +119,7 @@ class BeanDefinitionPropertyValueCodeGenerator { @@ -119,7 +119,7 @@ class BeanDefinitionPropertyValueCodeGenerator {
/**
* {@link Delegate} for {@code primitive} types.
*/
private class PrimitiveDelegate implements Delegate {
private static class PrimitiveDelegate implements Delegate {
private static final Map<Character, String> CHAR_ESCAPES;
@ -177,7 +177,7 @@ class BeanDefinitionPropertyValueCodeGenerator { @@ -177,7 +177,7 @@ class BeanDefinitionPropertyValueCodeGenerator {
/**
* {@link Delegate} for {@link String} types.
*/
private class StringDelegate implements Delegate {
private static class StringDelegate implements Delegate {
@Override
@Nullable
@ -194,7 +194,7 @@ class BeanDefinitionPropertyValueCodeGenerator { @@ -194,7 +194,7 @@ class BeanDefinitionPropertyValueCodeGenerator {
/**
* {@link Delegate} for {@link Enum} types.
*/
private class EnumDelegate implements Delegate {
private static class EnumDelegate implements Delegate {
@Override
@Nullable
@ -212,7 +212,7 @@ class BeanDefinitionPropertyValueCodeGenerator { @@ -212,7 +212,7 @@ class BeanDefinitionPropertyValueCodeGenerator {
/**
* {@link Delegate} for {@link Class} types.
*/
private class ClassDelegate implements Delegate {
private static class ClassDelegate implements Delegate {
@Override
@Nullable
@ -229,7 +229,7 @@ class BeanDefinitionPropertyValueCodeGenerator { @@ -229,7 +229,7 @@ class BeanDefinitionPropertyValueCodeGenerator {
/**
* {@link Delegate} for {@link ResolvableType} types.
*/
private class ResolvableTypeDelegate implements Delegate {
private static class ResolvableTypeDelegate implements Delegate {
@Override
@Nullable
@ -512,7 +512,7 @@ class BeanDefinitionPropertyValueCodeGenerator { @@ -512,7 +512,7 @@ class BeanDefinitionPropertyValueCodeGenerator {
/**
* {@link Delegate} for {@link BeanReference} types.
*/
private class BeanReferenceDelegate implements Delegate {
private static class BeanReferenceDelegate implements Delegate {
@Override
@Nullable

2
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

@ -509,7 +509,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo @@ -509,7 +509,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
}
private class AotContribution implements BeanFactoryInitializationAotContribution {
private static class AotContribution implements BeanFactoryInitializationAotContribution {
private static final String BEAN_FACTORY_VARIABLE = BeanFactoryInitializationCode.BEAN_FACTORY_VARIABLE;

Loading…
Cancel
Save