Skip to content

Commit

Permalink
Eliminate redundant lookups of classes and annotations during bean in…
Browse files Browse the repository at this point in the history
…stantiation

Closes spring-projectsgh-30883
  • Loading branch information
jengebr committed Jul 14, 2023
1 parent 37ac3d8 commit 7fbe3ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Expand Up @@ -48,6 +48,8 @@ public class InjectionPoint {
@Nullable
private volatile Annotation[] fieldAnnotations;

@Nullable
private volatile Annotation[] methodParameterAnnotations;

/**
* Create an injection point descriptor for a method or constructor parameter.
Expand Down Expand Up @@ -76,6 +78,7 @@ protected InjectionPoint(InjectionPoint original) {
new MethodParameter(original.methodParameter) : null);
this.field = original.field;
this.fieldAnnotations = original.fieldAnnotations;
this.methodParameterAnnotations = original.methodParameterAnnotations;
}

/**
Expand Down Expand Up @@ -129,7 +132,13 @@ public Annotation[] getAnnotations() {
return fieldAnnotations;
}
else {
return obtainMethodParameter().getParameterAnnotations();
Annotation[] methodParameterAnnotations = this.methodParameterAnnotations;
if (methodParameterAnnotations == null) {
methodParameterAnnotations =
obtainMethodParameter().getParameterAnnotations();
this.methodParameterAnnotations = methodParameterAnnotations;
}
return methodParameterAnnotations;
}
}

Expand Down
Expand Up @@ -155,7 +155,8 @@ public Object[] getArguments() {
* @see #invoke
*/
public void prepare() throws ClassNotFoundException, NoSuchMethodException {
if (this.staticMethod != null) {
Class<?> targetClass = getTargetClass();
if (targetClass == null && this.staticMethod != null) {
int lastDotIndex = this.staticMethod.lastIndexOf('.');
if (lastDotIndex == -1 || lastDotIndex == this.staticMethod.length()) {
throw new IllegalArgumentException(
Expand All @@ -164,11 +165,12 @@ public void prepare() throws ClassNotFoundException, NoSuchMethodException {
}
String className = this.staticMethod.substring(0, lastDotIndex);
String methodName = this.staticMethod.substring(lastDotIndex + 1);
this.targetClass = resolveClassName(className);
targetClass = resolveClassName(className);
this.targetClass = targetClass;
this.targetMethod = methodName;

}

Class<?> targetClass = getTargetClass();
String targetMethod = getTargetMethod();
Assert.notNull(targetClass, "Either 'targetClass' or 'targetObject' is required");
Assert.notNull(targetMethod, "Property 'targetMethod' is required");
Expand Down

0 comments on commit 7fbe3ec

Please sign in to comment.