Eclipse RCP 中覆盖 getWorkbenchErrorHandler 的意外行为
我想我在代码中发现了一种薛定谔猫问题。如果我更改同一函数体内的一行,则该函数的正文永远不会执行;但如果我不理会该行,该函数就会执行。不知何故,程序提前知道主体是什么,并决定不调用它...
我正在 Java 中开发 Eclipse RCP 应用程序,并且需要使用他们的 错误处理系统。根据链接的页面,
有两种方法可以将处理程序添加到处理流程中。
- 使用扩展点 org.eclipse.ui.statusHandlers
- 由工作台顾问程序及其方法 {@link WorkbenchAdvisor#getWorkbenchErrorHandler()} 实现。
。因此,我进入了我的 ApplicationWorkbenchAdvisor
类,并重写了 getWorkbenchErrorHandler
方法:
@Override
public synchronized AbstractStatusHandler getWorkbenchErrorHandler()
{
System.out.println("IT LIVES!");
if (myErrorHandler == null)
{
AbstractStatusHandler delegate = super.getWorkbenchErrorHandler();
MyStatusHandler otherThing = new MyStatusHandler(delegate);
myErrorHandler = otherThing;
}
return myErrorHandler;
}
MyStatusHandler
旨在充当 >委托
处理程序。为了匿名,我已重新命名该类。事实上,上面这个函数从未被调用过。 println 永远不会发生,即使在带有断点的调试模式下,它们也永远不会触发。现在是奇怪的部分:如果我更改分配 myErrorHandler
的行,
myErrorHandler = delegate;
则调用该函数;事实上,多次!
这个问题把我和两个精通java的同事难住了,所以我希望SO的好心人可以帮助我们!
I think I've discovered a kind of Schrödinger's cat problem in my code. The body of a function is never executed if I change one line within the body of that same function; but if I leave that line alone, the function executes. Somehow the program knows ahead of time what the body is, and decides not to call it...
I'm working on an Eclipse RCP application in Java, and have need to use their Error Handling System. According to the page linked,
There are two ways for adding handlers to the handling flow.
- using extension point org.eclipse.ui.statusHandlers
- by the workbench advisor and its method {@link WorkbenchAdvisor#getWorkbenchErrorHandler()}.
So I've gone into my ApplicationWorkbenchAdvisor
class, and overridden the getWorkbenchErrorHandler
method:
@Override
public synchronized AbstractStatusHandler getWorkbenchErrorHandler()
{
System.out.println("IT LIVES!");
if (myErrorHandler == null)
{
AbstractStatusHandler delegate = super.getWorkbenchErrorHandler();
MyStatusHandler otherThing = new MyStatusHandler(delegate);
myErrorHandler = otherThing;
}
return myErrorHandler;
}
The MyStatusHandler
is meant to act as a wrapper for the delegate
handler. I've re-named the class for anonymity. As it is, above, this function is never called. The println never happens, and even in debug mode with breakpoints, they never trigger. Now the wierd part: If I change the line that assigns the myErrorHandler
to
myErrorHandler = delegate;
then the function is called; multiple times, in fact!
This problem has me and two java-savvy coworkers stumped, so I'm hoping the good people of SO can help us!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我的问题是
MyErrorHandler
类是在不同的插件中定义的,该插件可能尚未完全加载。这似乎并不完全一致,但是一旦我将错误处理程序的类定义移动到启动期间调用它的同一个插件中,问题就消失了。As it turned out, my problem was that the
MyErrorHandler
class was defined in a different plugin, which presumably wasn't fully loaded yet. That doesn't seem to add up entirely, but once I moved the class definition of my error handler into the same plugin that was calling it during startup, the problems went away.