From f32f04d841012b04ed34923f62f783f095284402 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 28 Sep 2021 19:02:44 +0200 Subject: [PATCH] Code cleanup on new baseline --- .../ParameterResolutionDelegate.java | 46 ++----------------- .../CommonAnnotationBeanPostProcessor.java | 4 +- .../apache/commons/logging/LogAdapter.java | 5 +- 3 files changed, 9 insertions(+), 46 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/ParameterResolutionDelegate.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/ParameterResolutionDelegate.java index fc212da6c6..5f5d1a9d82 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/ParameterResolutionDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/ParameterResolutionDelegate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 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. @@ -18,7 +18,6 @@ package org.springframework.beans.factory.annotation; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Constructor; import java.lang.reflect.Executable; import java.lang.reflect.Parameter; @@ -30,7 +29,6 @@ import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.SynthesizingMethodParameter; import org.springframework.lang.Nullable; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; /** * Public delegate for resolving autowirable parameters on externally managed @@ -81,10 +79,9 @@ public final class ParameterResolutionDelegate { */ public static boolean isAutowirable(Parameter parameter, int parameterIndex) { Assert.notNull(parameter, "Parameter must not be null"); - AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex); - return (AnnotatedElementUtils.hasAnnotation(annotatedParameter, Autowired.class) || - AnnotatedElementUtils.hasAnnotation(annotatedParameter, Qualifier.class) || - AnnotatedElementUtils.hasAnnotation(annotatedParameter, Value.class)); + return (AnnotatedElementUtils.hasAnnotation(parameter, Autowired.class) || + AnnotatedElementUtils.hasAnnotation(parameter, Qualifier.class) || + AnnotatedElementUtils.hasAnnotation(parameter, Value.class)); } /** @@ -125,8 +122,7 @@ public final class ParameterResolutionDelegate { Assert.notNull(containingClass, "Containing class must not be null"); Assert.notNull(beanFactory, "AutowireCapableBeanFactory must not be null"); - AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex); - Autowired autowired = AnnotatedElementUtils.findMergedAnnotation(annotatedParameter, Autowired.class); + Autowired autowired = AnnotatedElementUtils.findMergedAnnotation(parameter, Autowired.class); boolean required = (autowired == null || autowired.required()); MethodParameter methodParameter = SynthesizingMethodParameter.forExecutable( @@ -136,36 +132,4 @@ public final class ParameterResolutionDelegate { return beanFactory.resolveDependency(descriptor, null); } - /** - * Due to a bug in {@code javac} on JDK versions prior to JDK 9, looking up - * annotations directly on a {@link Parameter} will fail for inner class - * constructors. - *

Bug in javac in JDK < 9

- *

The parameter annotations array in the compiled byte code excludes an entry - * for the implicit enclosing instance parameter for an inner class - * constructor. - *

Workaround

- *

This method provides a workaround for this off-by-one error by allowing the - * caller to access annotations on the preceding {@link Parameter} object (i.e., - * {@code index - 1}). If the supplied {@code index} is zero, this method returns - * an empty {@code AnnotatedElement}. - *

WARNING

- *

The {@code AnnotatedElement} returned by this method should never be cast and - * treated as a {@code Parameter} since the metadata (e.g., {@link Parameter#getName()}, - * {@link Parameter#getType()}, etc.) will not match those for the declared parameter - * at the given index in an inner class constructor. - * @return the supplied {@code parameter} or the effective {@code Parameter} - * if the aforementioned bug is in effect - */ - private static AnnotatedElement getEffectiveAnnotatedParameter(Parameter parameter, int index) { - Executable executable = parameter.getDeclaringExecutable(); - if (executable instanceof Constructor && ClassUtils.isInnerClass(executable.getDeclaringClass()) && - executable.getParameterAnnotations().length == executable.getParameterCount() - 1) { - // Bug in javac in JDK <9: annotation array excludes enclosing instance parameter - // for inner classes, so access it with the actual parameter index lowered by 1 - return (index == 0 ? EMPTY_ANNOTATED_ELEMENT : executable.getParameters()[index - 1]); - } - return parameter; - } - } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java index c3ded8c56f..c3efdfbed2 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java @@ -227,7 +227,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean /** * Specify the factory for objects to be injected into {@code @Resource} / - * {@code @WebServiceRef} / {@code @EJB} annotated fields and setter methods, + * {@code @EJB} annotated fields and setter methods, * for {@code mappedName} attributes that point directly into JNDI. * This factory will also be used if "alwaysUseJndiLookup" is set to "true" in order * to enforce JNDI lookups even for {@code name} attributes and default names. @@ -243,7 +243,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean /** * Specify the factory for objects to be injected into {@code @Resource} / - * {@code @WebServiceRef} / {@code @EJB} annotated fields and setter methods, + * {@code @EJB} annotated fields and setter methods, * for {@code name} attributes and default names. *

The default is the BeanFactory that this post-processor is defined in, * if any, looking up resource names as Spring bean names. Specify the resource diff --git a/spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java b/spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java index 5639cc0f6d..09ae22efe0 100644 --- a/spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java +++ b/spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java @@ -681,7 +681,6 @@ final class LogAdapter { setSourceMethodName(sourceMethodName); } - @SuppressWarnings("deprecation") protected Object writeReplace() { LogRecord serialized = new LogRecord(getLevel(), getMessage()); serialized.setLoggerName(getLoggerName()); @@ -691,8 +690,8 @@ final class LogAdapter { serialized.setSourceMethodName(getSourceMethodName()); serialized.setSequenceNumber(getSequenceNumber()); serialized.setParameters(getParameters()); - serialized.setThreadID(getThreadID()); - serialized.setMillis(getMillis()); + serialized.setLongThreadID(getLongThreadID()); + serialized.setInstant(getInstant()); serialized.setThrown(getThrown()); return serialized; }