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,
我正在使用Java编写Eclipse RCP应用程序,并且需要使用他们的错误处理系统。根据页面链接,
There are two ways for adding handlers to the handling flow.
有两种方法可以将处理程序添加到处理流程中。
- using extension point org.eclipse.ui.statusHandlers
使用扩展点org.eclipse.ui.statusHandlers
- by the workbench advisor and its method {@link WorkbenchAdvisor#getWorkbenchErrorHandler()}.
由workbench顾问及其方法{@link WorkbenchAdvisor#getWorkbenchErrorHandler()}。
So I've gone into my ApplicationWorkbenchAdvisor
class, and overridden the getWorkbenchErrorHandler
method:
所以我进入了我的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;
}
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
MyStatusHandler用作委托处理程序的包装器。我已经将这个班级重新命名为匿名。如上所述,从不调用此函数。 println永远不会发生,即使在带有断点的调试模式下,它们也永远不会触发。现在是奇怪的部分:如果我改变了分配myErrorHandler的行
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!
这个问题让我和两个精通java的同事难以理解,所以我希望SO的优秀人才能帮到我们!
1 个解决方案
#1
0
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.
事实证明,我的问题是MyErrorHandler类是在一个不同的插件中定义的,可能还没有完全加载。这似乎并没有完全相加,但是一旦我将错误处理程序的类定义移动到启动期间调用它的同一个插件中,问题就消失了。
#1
0
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.
事实证明,我的问题是MyErrorHandler类是在一个不同的插件中定义的,可能还没有完全加载。这似乎并没有完全相加,但是一旦我将错误处理程序的类定义移动到启动期间调用它的同一个插件中,问题就消失了。