From ee832206dc5a55e75c173c3d096ef331666bd140 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 13 Mar 2020 23:41:42 +0100 Subject: [PATCH] Polishing --- .../aop/framework/CglibAopProxy.java | 22 ++++++++++--------- .../factory/support/AbstractBeanFactory.java | 6 ++--- .../annotation/AutoProxyRegistrar.java | 5 +++-- .../codec/json/AbstractJackson2Encoder.java | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java index b87aa3aabf5..0a3cf5131be 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -258,15 +258,17 @@ class CglibAopProxy implements AopProxy, Serializable { int mod = method.getModifiers(); if (!Modifier.isStatic(mod) && !Modifier.isPrivate(mod)) { if (Modifier.isFinal(mod)) { - if (implementsInterface(method, ifcs)) { + if (logger.isInfoEnabled() && implementsInterface(method, ifcs)) { logger.info("Unable to proxy interface-implementing method [" + method + "] because " + "it is marked as final: Consider using interface-based JDK proxies instead!"); } - logger.debug("Final method [" + method + "] cannot get proxied via CGLIB: " + - "Calls to this method will NOT be routed to the target instance and " + - "might lead to NPEs against uninitialized fields in the proxy instance."); + if (logger.isDebugEnabled()) { + logger.debug("Final method [" + method + "] cannot get proxied via CGLIB: " + + "Calls to this method will NOT be routed to the target instance and " + + "might lead to NPEs against uninitialized fields in the proxy instance."); + } } - else if (!Modifier.isPublic(mod) && !Modifier.isProtected(mod) && + else if (logger.isDebugEnabled() && !Modifier.isPublic(mod) && !Modifier.isProtected(mod) && proxyClassLoader != null && proxySuperClass.getClassLoader() != proxyClassLoader) { logger.debug("Method [" + method + "] is package-visible across different ClassLoaders " + "and cannot get proxied via CGLIB: Declare this method as public or protected " + @@ -526,7 +528,7 @@ class CglibAopProxy implements AopProxy, Serializable { private static class StaticDispatcher implements Dispatcher, Serializable { @Nullable - private Object target; + private final Object target; public StaticDispatcher(@Nullable Object target) { this.target = target; @@ -552,7 +554,7 @@ class CglibAopProxy implements AopProxy, Serializable { } @Override - public Object loadObject() throws Exception { + public Object loadObject() { return this.advised; } } @@ -940,11 +942,11 @@ class CglibAopProxy implements AopProxy, Serializable { return true; } - private boolean equalsAdviceClasses(Advisor a, Advisor b) { + private static boolean equalsAdviceClasses(Advisor a, Advisor b) { return (a.getAdvice().getClass() == b.getAdvice().getClass()); } - private boolean equalsPointcuts(Advisor a, Advisor b) { + private static boolean equalsPointcuts(Advisor a, Advisor b) { // If only one of the advisor (but not both) is PointcutAdvisor, then it is a mismatch. // Takes care of the situations where an IntroductionAdvisor is used (see SPR-3959). return (!(a instanceof PointcutAdvisor) || diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index e6fcceb9e49..3c5059a4f1b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -1283,7 +1283,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp else { throw new NoSuchBeanDefinitionException(parentBeanName, "Parent name '" + parentBeanName + "' is equal to bean name '" + beanName + - "': cannot be resolved without an AbstractBeanFactory parent"); + "': cannot be resolved without a ConfigurableBeanFactory parent"); } } } @@ -1298,7 +1298,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp // Set default singleton scope, if not configured before. if (!StringUtils.hasLength(mbd.getScope())) { - mbd.setScope(RootBeanDefinition.SCOPE_SINGLETON); + mbd.setScope(SCOPE_SINGLETON); } // A bean contained in a non-singleton bean cannot be a singleton itself. diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AutoProxyRegistrar.java b/spring-context/src/main/java/org/springframework/context/annotation/AutoProxyRegistrar.java index 33c5e3907b1..2e5fa3dc130 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/AutoProxyRegistrar.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/AutoProxyRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -33,7 +33,8 @@ import org.springframework.core.type.AnnotationMetadata; * * @author Chris Beams * @since 3.1 - * @see EnableAspectJAutoProxy + * @see org.springframework.cache.annotation.EnableCaching + * @see org.springframework.transaction.annotation.EnableTransactionManagement */ public class AutoProxyRegistrar implements ImportBeanDefinitionRegistrar { diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java b/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java index 621405cfd00..309a79c1a26 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java @@ -70,7 +70,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple private static final Map STREAM_SEPARATORS; static { - STREAM_SEPARATORS = new HashMap<>(); + STREAM_SEPARATORS = new HashMap<>(4); STREAM_SEPARATORS.put(MediaType.APPLICATION_STREAM_JSON, NEWLINE_SEPARATOR); STREAM_SEPARATORS.put(MediaType.parseMediaType("application/stream+x-jackson-smile"), new byte[0]); }