gpt4 book ai didi

java - Vaadin UI.access() 抛出 ExecutionException

转载 作者:搜寻专家 更新时间:2023-11-01 03:51:53 25 4
gpt4 key购买 nike

我在 Vaadin 项目中看到了这个异常。但是,功能并没有真正中断。 run() 方法中的代码执行了它想要完成的操作,但是出现了这个异常。

E 140619 124701.131 [Thread-2] MainUI - Uncaught throwable: 
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at com.vaadin.server.VaadinSession$FutureAccess.get(VaadinSession.java:123)
at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:1802)
at com.vaadin.server.VaadinSession.unlock(VaadinSession.java:1012)
at com.vaadin.server.VaadinService.ensureAccessQueuePurged(VaadinService.java:1763)
at com.vaadin.server.VaadinService.accessSession(VaadinService.java:1729)
at com.vaadin.server.VaadinSession.access(VaadinSession.java:1402)
at com.vaadin.ui.UI.access(UI.java:1372)

发生在这里

ui.acccess(new Runnable() {
@Override
public void run() {
//code here
}
}

我应该做什么?我可以只捕获异常并忽略它,还是我的代码中某处存在错误?

MainUI 使用@Push 注解扩展UI,代码如下:

@Override
protected void init(VaadinRequest request) {
WrappedSession wrappedSession = request.getWrappedSession();
final String id = wrappedSession.getId();
log.info("Created new UI for session id {}", id);

VaadinSession.getCurrent().setErrorHandler(new DefaultErrorHandler() {
@Override
public void error(com.vaadin.server.ErrorEvent event) {
super.error(event);
log.error("Uncaught throwable: ", event.getThrowable());
}
});

...
}

另一个例子

[此部分由其他作者添加]

我,Basil Bourque,在相同的用法中得到了似乎相同的异常。在生产使用(而非开发)中抛出异常。

在 Mac OS X Mountain Lion 上的 Java 8 Update 20 上使用 Vaadin 7.1.3 和 Tomcat 8.0.12 推送。

异常(exception):

Nov 04, 2014 4:45:50 AM com.vaadin.server.DefaultErrorHandler doDefault
SEVERE:
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at com.vaadin.server.VaadinSession$FutureAccess.get(VaadinSession.java:123)
at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:1800)
at com.vaadin.server.VaadinSession.unlock(VaadinSession.java:1013)
at com.vaadin.server.VaadinService.ensureAccessQueuePurged(VaadinService.java:1761)
at com.vaadin.server.VaadinService.accessSession(VaadinService.java:1727)
at com.vaadin.server.VaadinSession.access(VaadinSession.java:1403)
at com.vaadin.ui.UI.access(UI.java:1389)
at com.rainwatersoft.powerwrangler.curr_sup_dem.CurrSupDemReportUpdater.update(CurrSupDemReportUpdater.java:164)
at com.rainwatersoft.powerwrangler.curr_sup_dem.CurrSupDemReportUpdater.checkForUpdate(CurrSupDemReportUpdater.java:125)
at com.rainwatersoft.powerwrangler.curr_sup_dem.CurrSupDemReportUpdater.lambda$considerUpdate$2(CurrSupDemReportUpdater.java:110)
at com.rainwatersoft.powerwrangler.curr_sup_dem.CurrSupDemReportUpdater$$Lambda$3/1011224121.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException

违规代码使用 Java 8 的 Lambda 语法将 Runnable 传递给 UI::access方法。

layout.getUI().access( () -> { // Runnable
layout.freshen( this.interval );
} );

最佳答案

这是我的代码的摘录:

// remember UI and request attributes
val ui = UI.getCurrent
val attributes = RequestContextHolder.getRequestAttributes

future.onSuccess {
case e => ui.access(
new Runnable {
override def run(): Unit = {
try {
RequestContextHolder.setRequestAttributes(attributes)
success.apply(e)
} finally {
RequestContextHolder.resetRequestAttributes()
}
}
}
)
}

future.onFailure {
case t => ui.access(
new Runnable {
override def run(): Unit = {
try {
_logger.error("Something goes wrong in async await request", t)
RequestContextHolder.setRequestAttributes(attributes)
failure.apply(t)
} finally {
RequestContextHolder.resetRequestAttributes()
}
}
}
)
}

我将 spring4vaadin 与最新的 Vaadin 7.2.x 结合使用。

关于java - Vaadin UI.access() 抛出 ExecutionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24381762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com