Skip to content

Commit 7cb6ac0

Browse files
missingdayssbrannen
authored andcommitted
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 spring-projectsgh-28433
1 parent d45b5f6 commit 7cb6ac0

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ private Object resolvedCachedArgument(@Nullable String beanName, @Nullable Objec
654654
/**
655655
* Base class representing injection information.
656656
*/
657-
private abstract class AutowiredElement extends InjectionMetadata.InjectedElement {
657+
private abstract static class AutowiredElement extends InjectionMetadata.InjectedElement {
658658

659659
protected final boolean required;
660660

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private interface Delegate {
119119
/**
120120
* {@link Delegate} for {@code primitive} types.
121121
*/
122-
private class PrimitiveDelegate implements Delegate {
122+
private static class PrimitiveDelegate implements Delegate {
123123

124124
private static final Map<Character, String> CHAR_ESCAPES;
125125

@@ -177,7 +177,7 @@ private String escape(char ch) {
177177
/**
178178
* {@link Delegate} for {@link String} types.
179179
*/
180-
private class StringDelegate implements Delegate {
180+
private static class StringDelegate implements Delegate {
181181

182182
@Override
183183
@Nullable
@@ -194,7 +194,7 @@ public CodeBlock generateCode(Object value, ResolvableType type) {
194194
/**
195195
* {@link Delegate} for {@link Enum} types.
196196
*/
197-
private class EnumDelegate implements Delegate {
197+
private static class EnumDelegate implements Delegate {
198198

199199
@Override
200200
@Nullable
@@ -212,7 +212,7 @@ public CodeBlock generateCode(Object value, ResolvableType type) {
212212
/**
213213
* {@link Delegate} for {@link Class} types.
214214
*/
215-
private class ClassDelegate implements Delegate {
215+
private static class ClassDelegate implements Delegate {
216216

217217
@Override
218218
@Nullable
@@ -229,7 +229,7 @@ public CodeBlock generateCode(Object value, ResolvableType type) {
229229
/**
230230
* {@link Delegate} for {@link ResolvableType} types.
231231
*/
232-
private class ResolvableTypeDelegate implements Delegate {
232+
private static class ResolvableTypeDelegate implements Delegate {
233233

234234
@Override
235235
@Nullable
@@ -512,7 +512,7 @@ private <K, V> CodeBlock generateLinkedHashMapCode(Map<K, V> map,
512512
/**
513513
* {@link Delegate} for {@link BeanReference} types.
514514
*/
515-
private class BeanReferenceDelegate implements Delegate {
515+
private static class BeanReferenceDelegate implements Delegate {
516516

517517
@Override
518518
@Nullable

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) {
509509
}
510510

511511

512-
private class AotContribution implements BeanFactoryInitializationAotContribution {
512+
private static class AotContribution implements BeanFactoryInitializationAotContribution {
513513

514514
private static final String BEAN_FACTORY_VARIABLE = BeanFactoryInitializationCode.BEAN_FACTORY_VARIABLE;
515515

0 commit comments

Comments
 (0)