Skip to content

Commit f32f04d

Browse files
committed
Code cleanup on new baseline
1 parent 4d7fa9a commit f32f04d

File tree

3 files changed

+9
-46
lines changed

3 files changed

+9
-46
lines changed

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

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
1818

1919
import java.lang.annotation.Annotation;
2020
import java.lang.reflect.AnnotatedElement;
21-
import java.lang.reflect.Constructor;
2221
import java.lang.reflect.Executable;
2322
import java.lang.reflect.Parameter;
2423

@@ -30,7 +29,6 @@
3029
import org.springframework.core.annotation.SynthesizingMethodParameter;
3130
import org.springframework.lang.Nullable;
3231
import org.springframework.util.Assert;
33-
import org.springframework.util.ClassUtils;
3432

3533
/**
3634
* Public delegate for resolving autowirable parameters on externally managed
@@ -81,10 +79,9 @@ private ParameterResolutionDelegate() {
8179
*/
8280
public static boolean isAutowirable(Parameter parameter, int parameterIndex) {
8381
Assert.notNull(parameter, "Parameter must not be null");
84-
AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex);
85-
return (AnnotatedElementUtils.hasAnnotation(annotatedParameter, Autowired.class) ||
86-
AnnotatedElementUtils.hasAnnotation(annotatedParameter, Qualifier.class) ||
87-
AnnotatedElementUtils.hasAnnotation(annotatedParameter, Value.class));
82+
return (AnnotatedElementUtils.hasAnnotation(parameter, Autowired.class) ||
83+
AnnotatedElementUtils.hasAnnotation(parameter, Qualifier.class) ||
84+
AnnotatedElementUtils.hasAnnotation(parameter, Value.class));
8885
}
8986

9087
/**
@@ -125,8 +122,7 @@ public static Object resolveDependency(
125122
Assert.notNull(containingClass, "Containing class must not be null");
126123
Assert.notNull(beanFactory, "AutowireCapableBeanFactory must not be null");
127124

128-
AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex);
129-
Autowired autowired = AnnotatedElementUtils.findMergedAnnotation(annotatedParameter, Autowired.class);
125+
Autowired autowired = AnnotatedElementUtils.findMergedAnnotation(parameter, Autowired.class);
130126
boolean required = (autowired == null || autowired.required());
131127

132128
MethodParameter methodParameter = SynthesizingMethodParameter.forExecutable(
@@ -136,36 +132,4 @@ public static Object resolveDependency(
136132
return beanFactory.resolveDependency(descriptor, null);
137133
}
138134

139-
/**
140-
* Due to a bug in {@code javac} on JDK versions prior to JDK 9, looking up
141-
* annotations directly on a {@link Parameter} will fail for inner class
142-
* constructors.
143-
* <h4>Bug in javac in JDK &lt; 9</h4>
144-
* <p>The parameter annotations array in the compiled byte code excludes an entry
145-
* for the implicit <em>enclosing instance</em> parameter for an inner class
146-
* constructor.
147-
* <h4>Workaround</h4>
148-
* <p>This method provides a workaround for this off-by-one error by allowing the
149-
* caller to access annotations on the preceding {@link Parameter} object (i.e.,
150-
* {@code index - 1}). If the supplied {@code index} is zero, this method returns
151-
* an empty {@code AnnotatedElement}.
152-
* <h4>WARNING</h4>
153-
* <p>The {@code AnnotatedElement} returned by this method should never be cast and
154-
* treated as a {@code Parameter} since the metadata (e.g., {@link Parameter#getName()},
155-
* {@link Parameter#getType()}, etc.) will not match those for the declared parameter
156-
* at the given index in an inner class constructor.
157-
* @return the supplied {@code parameter} or the <em>effective</em> {@code Parameter}
158-
* if the aforementioned bug is in effect
159-
*/
160-
private static AnnotatedElement getEffectiveAnnotatedParameter(Parameter parameter, int index) {
161-
Executable executable = parameter.getDeclaringExecutable();
162-
if (executable instanceof Constructor && ClassUtils.isInnerClass(executable.getDeclaringClass()) &&
163-
executable.getParameterAnnotations().length == executable.getParameterCount() - 1) {
164-
// Bug in javac in JDK <9: annotation array excludes enclosing instance parameter
165-
// for inner classes, so access it with the actual parameter index lowered by 1
166-
return (index == 0 ? EMPTY_ANNOTATED_ELEMENT : executable.getParameters()[index - 1]);
167-
}
168-
return parameter;
169-
}
170-
171135
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public void setAlwaysUseJndiLookup(boolean alwaysUseJndiLookup) {
227227

228228
/**
229229
* Specify the factory for objects to be injected into {@code @Resource} /
230-
* {@code @WebServiceRef} / {@code @EJB} annotated fields and setter methods,
230+
* {@code @EJB} annotated fields and setter methods,
231231
* <b>for {@code mappedName} attributes that point directly into JNDI</b>.
232232
* This factory will also be used if "alwaysUseJndiLookup" is set to "true" in order
233233
* to enforce JNDI lookups even for {@code name} attributes and default names.
@@ -243,7 +243,7 @@ public void setJndiFactory(BeanFactory jndiFactory) {
243243

244244
/**
245245
* Specify the factory for objects to be injected into {@code @Resource} /
246-
* {@code @WebServiceRef} / {@code @EJB} annotated fields and setter methods,
246+
* {@code @EJB} annotated fields and setter methods,
247247
* <b>for {@code name} attributes and default names</b>.
248248
* <p>The default is the BeanFactory that this post-processor is defined in,
249249
* if any, looking up resource names as Spring bean names. Specify the resource

spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ else if (found) {
681681
setSourceMethodName(sourceMethodName);
682682
}
683683

684-
@SuppressWarnings("deprecation")
685684
protected Object writeReplace() {
686685
LogRecord serialized = new LogRecord(getLevel(), getMessage());
687686
serialized.setLoggerName(getLoggerName());
@@ -691,8 +690,8 @@ protected Object writeReplace() {
691690
serialized.setSourceMethodName(getSourceMethodName());
692691
serialized.setSequenceNumber(getSequenceNumber());
693692
serialized.setParameters(getParameters());
694-
serialized.setThreadID(getThreadID());
695-
serialized.setMillis(getMillis());
693+
serialized.setLongThreadID(getLongThreadID());
694+
serialized.setInstant(getInstant());
696695
serialized.setThrown(getThrown());
697696
return serialized;
698697
}

0 commit comments

Comments
 (0)