diff --git a/spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfigurer.java b/spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfigurer.java index ca0a9d8f6b6..747465bbb56 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfigurer.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2023 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. @@ -21,8 +21,8 @@ import org.springframework.instrument.classloading.LoadTimeWeaver; /** * Interface to be implemented by * {@link org.springframework.context.annotation.Configuration @Configuration} - * classes annotated with {@link EnableLoadTimeWeaving @EnableLoadTimeWeaving} that wish to - * customize the {@link LoadTimeWeaver} instance to be used. + * classes annotated with {@link EnableLoadTimeWeaving @EnableLoadTimeWeaving} + * that wish to customize the {@link LoadTimeWeaver} instance to be used. * *

See {@link org.springframework.scheduling.annotation.EnableAsync @EnableAsync} * for usage examples and information on how a default {@code LoadTimeWeaver} @@ -36,9 +36,9 @@ import org.springframework.instrument.classloading.LoadTimeWeaver; public interface LoadTimeWeavingConfigurer { /** - * Create, configure and return the {@code LoadTimeWeaver} instance to be used. Note - * that it is unnecessary to annotate this method with {@code @Bean}, because the - * object returned will automatically be registered as a bean by + * Create, configure and return the {@code LoadTimeWeaver} instance to be used. + * Note that it is unnecessary to annotate this method with {@code @Bean} + * because the object returned will automatically be registered as a bean by * {@link LoadTimeWeavingConfiguration#loadTimeWeaver()} */ LoadTimeWeaver getLoadTimeWeaver(); diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index 00bccae17b8..62eafb34da7 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java @@ -772,7 +772,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader // Detect a LoadTimeWeaver and prepare for weaving, if found in the meantime // (e.g. through an @Bean method registered by ConfigurationClassPostProcessor) - if (!NativeDetector.inNativeImage() && beanFactory.getTempClassLoader() == null && beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) { + if (!NativeDetector.inNativeImage() && beanFactory.getTempClassLoader() == null && + beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) { beanFactory.addBeanPostProcessor(new LoadTimeWeaverAwareProcessor(beanFactory)); beanFactory.setTempClassLoader(new ContextTypeMatchClassLoader(beanFactory.getBeanClassLoader())); } diff --git a/spring-context/src/test/java/org/springframework/context/annotation/EnableLoadTimeWeavingTests.java b/spring-context/src/test/java/org/springframework/context/annotation/EnableLoadTimeWeavingTests.java index b845a68efca..58c8d8753f4 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/EnableLoadTimeWeavingTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/EnableLoadTimeWeavingTests.java @@ -79,7 +79,7 @@ class EnableLoadTimeWeavingTests { @Configuration - @EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.DISABLED) + @EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.DISABLED) static class EnableLTWConfig_withAjWeavingDisabled implements LoadTimeWeavingConfigurer { @Override @@ -88,8 +88,9 @@ class EnableLoadTimeWeavingTests { } } + @Configuration - @EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.AUTODETECT) + @EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.AUTODETECT) static class EnableLTWConfig_withAjWeavingAutodetect implements LoadTimeWeavingConfigurer { @Override @@ -98,8 +99,9 @@ class EnableLoadTimeWeavingTests { } } + @Configuration - @EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.ENABLED) + @EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.ENABLED) static class EnableLTWConfig_withAjWeavingEnabled implements LoadTimeWeavingConfigurer { @Override diff --git a/spring-context/src/test/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaverTests.java b/spring-context/src/test/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaverTests.java index 448f71572ac..989b1e196de 100644 --- a/spring-context/src/test/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaverTests.java +++ b/spring-context/src/test/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2023 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. @@ -85,16 +85,13 @@ public class ReflectiveLoadTimeWeaverTests { private int numTimesAddTransformerCalled = 0; - public int getNumTimesGetThrowawayClassLoaderCalled() { return this.numTimesAddTransformerCalled; } - public void addTransformer(ClassFileTransformer transformer) { ++this.numTimesAddTransformerCalled; } - } @@ -102,18 +99,15 @@ public class ReflectiveLoadTimeWeaverTests { private int numTimesGetThrowawayClassLoaderCalled = 0; - @Override public int getNumTimesGetThrowawayClassLoaderCalled() { return this.numTimesGetThrowawayClassLoaderCalled; } - public ClassLoader getThrowawayClassLoader() { ++this.numTimesGetThrowawayClassLoaderCalled; return getClass().getClassLoader(); } - } } diff --git a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java index 18dd5396df8..0fdbb75d476 100644 --- a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -507,16 +507,8 @@ public abstract class ReflectionUtils { * @see java.lang.Object#equals(Object) */ public static boolean isEqualsMethod(@Nullable Method method) { - if (method == null) { - return false; - } - if (method.getParameterCount() != 1) { - return false; - } - if (!method.getName().equals("equals")) { - return false; - } - return method.getParameterTypes()[0] == Object.class; + return (method != null && method.getParameterCount() == 1 && method.getName().equals("equals") && + method.getParameterTypes()[0] == Object.class); } /** @@ -524,7 +516,7 @@ public abstract class ReflectionUtils { * @see java.lang.Object#hashCode() */ public static boolean isHashCodeMethod(@Nullable Method method) { - return method != null && method.getParameterCount() == 0 && method.getName().equals("hashCode"); + return (method != null && method.getParameterCount() == 0 && method.getName().equals("hashCode")); } /**