Skip to content

Commit 95c43bb

Browse files
committed
Polish "Skip non-overridden methods of Object.class"
See gh-24649
1 parent b91179d commit 95c43bb

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java

+5-16
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ private Callback[] getCallbacks(Class<?> rootClass) throws Exception {
331331
aopInterceptor, // for normal advice
332332
targetInterceptor, // invoke target without considering advice, if optimized
333333
new SerializableNoOp(), // no override for methods mapped to this
334-
targetDispatcher,
335-
this.advisedDispatcher,
334+
targetDispatcher, this.advisedDispatcher,
336335
new EqualsInterceptor(this.advised),
337336
new HashCodeInterceptor(this.advised)
338337
};
@@ -343,14 +342,14 @@ private Callback[] getCallbacks(Class<?> rootClass) throws Exception {
343342
if (isStatic && isFrozen) {
344343
Method[] methods = rootClass.getMethods();
345344
int methodsCount = methods.length;
346-
ArrayList<Callback> fixedCallbacks = new ArrayList<>(methodsCount);
345+
List<Callback> fixedCallbacks = new ArrayList<>(methodsCount);
347346
this.fixedInterceptorMap = CollectionUtils.newHashMap(methodsCount);
348347

349348
int advicedMethodCount = methodsCount;
350349
for (int x = 0; x < methodsCount; x++) {
351350
Method method = methods[x];
352351
//do not create advices for non-overridden methods of java.lang.Object
353-
if (notOverriddenOfObject(method)) {
352+
if (method.getDeclaringClass() == Object.class) {
354353
advicedMethodCount--;
355354
continue;
356355
}
@@ -364,24 +363,14 @@ private Callback[] getCallbacks(Class<?> rootClass) throws Exception {
364363
// and fixedCallbacks into the callbacks array.
365364
Callback[] callbacks = new Callback[mainCallbacks.length + advicedMethodCount];
366365
System.arraycopy(mainCallbacks, 0, callbacks, 0, mainCallbacks.length);
367-
System.arraycopy(fixedCallbacks.toArray(), 0, callbacks, mainCallbacks.length, advicedMethodCount);
366+
System.arraycopy(fixedCallbacks.toArray(Callback[]::new), 0, callbacks,
367+
mainCallbacks.length, advicedMethodCount);
368368
this.fixedInterceptorOffset = mainCallbacks.length;
369369
return callbacks;
370370
}
371-
372371
return mainCallbacks;
373372
}
374373

375-
/**
376-
* Returns true if param is inherited from {@link Object} and not overridden in declaring class.
377-
* We use this to detect {@link Object#notify()}, {@link Object#notifyAll()}, {@link Object#getClass()} etc.
378-
* to skip creation of useless advices for them.
379-
* @param method to be checked
380-
* @return true in case {@code method} belongs to {@link Object}
381-
*/
382-
private static boolean notOverriddenOfObject(Method method) {
383-
return method.getDeclaringClass() == Object.class;
384-
}
385374

386375
@Override
387376
public boolean equals(@Nullable Object other) {

0 commit comments

Comments
 (0)