Eclipse RCP 中覆盖 getWorkbenchErrorHandler 的意外行为

发布于 2025-01-01 00:12:57 字数 1260 浏览 0 评论 0原文

我想我在代码中发现了一种薛定谔猫问题。如果我更改同一函数体内的一行,则该函数的正文永远不会执行;但如果我不理会该行,该函数就会执行。不知何故,程序提前知道主体是什么,并决定不调用它...

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绅士风度i 2025-01-08 00:12:57

事实证明,我的问题是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文