parent
a7a88371e7
commit
c4ec6aea68
|
@ -295,9 +295,11 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
|
|||
@Nullable
|
||||
protected Object doInvoke(Object... args) {
|
||||
Object bean = getTargetBean();
|
||||
// Detect package-protected NullBean instance through equals(null) check
|
||||
if (bean.equals(null)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ReflectionUtils.makeAccessible(this.method);
|
||||
try {
|
||||
return this.method.invoke(bean, args);
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package org.springframework.context.event;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -627,12 +625,13 @@ public class AnnotationDrivenEventListenerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void missingBeanDoesntCrash() {
|
||||
public void missingListenerBeanIgnored() {
|
||||
load(MissingEventListener.class);
|
||||
context.getBean(UseMissingEventListener.class);
|
||||
context.getBean(ApplicationEventMulticaster.class).multicastEvent(new TestEvent(this));
|
||||
}
|
||||
|
||||
|
||||
private void load(Class<?>... classes) {
|
||||
List<Class<?>> allClasses = new ArrayList<>();
|
||||
allClasses.add(BasicConfiguration.class);
|
||||
|
@ -1087,8 +1086,9 @@ public class AnnotationDrivenEventListenerTests {
|
|||
}
|
||||
|
||||
@Configuration
|
||||
@Import({UseMissingEventListener.class})
|
||||
@Import(UseMissingEventListener.class)
|
||||
public static class MissingEventListener {
|
||||
|
||||
@Bean
|
||||
public MyEventListener missing() {
|
||||
return null;
|
||||
|
@ -1096,17 +1096,16 @@ public class AnnotationDrivenEventListenerTests {
|
|||
}
|
||||
|
||||
@Component
|
||||
public static class MyEventListener implements Closeable {
|
||||
public static class MyEventListener {
|
||||
|
||||
@EventListener
|
||||
public void hear(TestEvent e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {}
|
||||
}
|
||||
|
||||
public static class UseMissingEventListener {
|
||||
|
||||
@Inject
|
||||
public UseMissingEventListener(Optional<MyEventListener> notHere) {
|
||||
if (notHere.isPresent()) {
|
||||
|
@ -1114,4 +1113,5 @@ public class AnnotationDrivenEventListenerTests {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue