提交 c4ec6aea 编写于 作者: J Juergen Hoeller

Fix Checkstyle violations

See gh-23784
上级 a7a88371
......@@ -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;
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() {
load(MissingEventListener.class);
context.getBean(UseMissingEventListener.class);
context.getBean(ApplicationEventMulticaster.class).multicastEvent(new TestEvent(this));
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,31 +1086,32 @@ public class AnnotationDrivenEventListenerTests {
}
@Configuration
@Import({UseMissingEventListener.class})
@Import(UseMissingEventListener.class)
public static class MissingEventListener {
@Bean
public MyEventListener missing() {
return null;
}
@Bean
public MyEventListener missing() {
return null;
}
}
@Component
public static class MyEventListener implements Closeable {
@EventListener
public void hear(TestEvent e) {
throw new AssertionError();
}
public static class MyEventListener {
@Override
public void close() throws IOException {}
@EventListener
public void hear(TestEvent e) {
throw new AssertionError();
}
}
public static class UseMissingEventListener {
@Inject
public UseMissingEventListener(Optional<MyEventListener> notHere) {
if (notHere.isPresent()) {
throw new AssertionError();
}
}
@Inject
public UseMissingEventListener(Optional<MyEventListener> notHere) {
if (notHere.isPresent()) {
throw new AssertionError();
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册