创建自定义 Toolkit 时,为什么 createFrame 在 OSX 上失败?

发布于 2024-08-13 08:47:13 字数 4862 浏览 5 评论 0原文

我们正在尝试扩展 UISpec4j 测试框架,以在运行测试时显示用户界面。因此,我们有一个自定义工具包,它包装了相关平台的本机工具包。我们设法让一切在 Windows XP 上运行良好,但是当在 OSX 上测试我们的更改时,我们的 createFrame 扩展似乎表现得很奇怪:

 public FramePeer createFrame(Frame target) {
   FramePeer resultc = new UISpecFramePeer(target);
   //super.createFrame(target);

   return resultc;
 }

本质上,我们想要创建一个 UISpecFramePeer 作为拦截类......以便 UISpec4j 可以询问 UI 中发生的情况。但在我们的更改中,我们还想显示 UI。因此,我们尝试使用本机工具包创建一个框架并将其包装在 UISpecFramePeer 中(上面的代码中未显示)。

当我们运行上面的代码时,测试会运行(正如我们所期望的),但显然没有显示任何内容。但是,当我们包含 super.createFrame(target) 时。我们得到以下异常:

SEVERE: Application class org.openshapa.OpenSHAPA failed to launch
java.lang.ClassCastException: org.uispec4j.interception.toolkit.UISpecFramePeer
    at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:236)
    at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:233)
    at apple.awt.ClientPropertyApplicator.attachAndApplyClientProperties(ClientPropertyApplicator.java:24)
    at apple.awt.CWindow$1.propertyChange(CWindow.java:190)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:341)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
    at java.awt.Component.firePropertyChange(Component.java:7277)
    at javax.swing.JComponent.addNotify(JComponent.java:4479)
    at javax.swing.JRootPane.addNotify(JRootPane.java:680)
    at java.awt.Container.addNotify(Container.java:2544)
    at java.awt.Window.addNotify(Window.java:467)
    at java.awt.Frame.addNotify(Frame.java:501)
    at java.awt.Window.pack(Window.java:485)
    at org.jdesktop.application.SingleFrameApplication.initRootPaneContainer(SingleFrameApplication.java:216)
    at org.jdesktop.application.SingleFrameApplication.show(SingleFrameApplication.java:463)
    at org.openshapa.OpenSHAPA.startup(OpenSHAPA.java:444)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Exception in thread "AWT-EventQueue-2" java.lang.Error: Application class org.openshapa.OpenSHAPA failed to launch
    at org.jdesktop.application.Application$1.run(Application.java:177)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Caused by: java.lang.ClassCastException: org.uispec4j.interception.toolkit.UISpecFramePeer
    at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:236)
    at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:233)
    at apple.awt.ClientPropertyApplicator.attachAndApplyClientProperties(ClientPropertyApplicator.java:24)
    at apple.awt.CWindow$1.propertyChange(CWindow.java:190)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:341)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
    at java.awt.Component.firePropertyChange(Component.java:7277)
    at javax.swing.JComponent.addNotify(JComponent.java:4479)
    at javax.swing.JRootPane.addNotify(JRootPane.java:680)
    at java.awt.Container.addNotify(Container.java:2544)
    at java.awt.Window.addNotify(Window.java:467)
    at java.awt.Frame.addNotify(Frame.java:501)
    at java.awt.Window.pack(Window.java:485)
    at org.jdesktop.application.SingleFrameApplication.initRootPaneContainer(SingleFrameApplication.java:216)
    at org.jdesktop.application.SingleFrameApplication.show(SingleFrameApplication.java:463)
    at org.openshapa.OpenSHAPA.startup(OpenSHAPA.java:444)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    ... 7 more

为什么简单地使用本机工具包创建一个框架(但不返回它)会创建一个异常,而当 super.createFrame 被注释时它会表现得正常?

We are trying to extend the UISpec4j testing framework to display the user interface when running tests. So we have a custom toolkit that wraps around the native toolkit for the relevant platform. We managed to get everything working well on windows XP, however when testing our changes on OSX, our extension of createFrame appears to behave oddly:

 public FramePeer createFrame(Frame target) {
   FramePeer resultc = new UISpecFramePeer(target);
   //super.createFrame(target);

   return resultc;
 }

Essentially with the above, we want to create a UISpecFramePeer as an interception class... So that UISpec4j can interrogate what is happening within the UI. But in our changes, we also want to display the UI. So we attempt this by creating a frame using the native toolkit and wrapping it in the UISpecFramePeer (not shown in the code above).

When we run the above code, the tests run (as we expect) but obviously nothing is displayed. However, when we include super.createFrame(target). We get the following exception:

SEVERE: Application class org.openshapa.OpenSHAPA failed to launch
java.lang.ClassCastException: org.uispec4j.interception.toolkit.UISpecFramePeer
    at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:236)
    at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:233)
    at apple.awt.ClientPropertyApplicator.attachAndApplyClientProperties(ClientPropertyApplicator.java:24)
    at apple.awt.CWindow$1.propertyChange(CWindow.java:190)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:341)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
    at java.awt.Component.firePropertyChange(Component.java:7277)
    at javax.swing.JComponent.addNotify(JComponent.java:4479)
    at javax.swing.JRootPane.addNotify(JRootPane.java:680)
    at java.awt.Container.addNotify(Container.java:2544)
    at java.awt.Window.addNotify(Window.java:467)
    at java.awt.Frame.addNotify(Frame.java:501)
    at java.awt.Window.pack(Window.java:485)
    at org.jdesktop.application.SingleFrameApplication.initRootPaneContainer(SingleFrameApplication.java:216)
    at org.jdesktop.application.SingleFrameApplication.show(SingleFrameApplication.java:463)
    at org.openshapa.OpenSHAPA.startup(OpenSHAPA.java:444)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Exception in thread "AWT-EventQueue-2" java.lang.Error: Application class org.openshapa.OpenSHAPA failed to launch
    at org.jdesktop.application.Application$1.run(Application.java:177)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Caused by: java.lang.ClassCastException: org.uispec4j.interception.toolkit.UISpecFramePeer
    at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:236)
    at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:233)
    at apple.awt.ClientPropertyApplicator.attachAndApplyClientProperties(ClientPropertyApplicator.java:24)
    at apple.awt.CWindow$1.propertyChange(CWindow.java:190)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:341)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
    at java.awt.Component.firePropertyChange(Component.java:7277)
    at javax.swing.JComponent.addNotify(JComponent.java:4479)
    at javax.swing.JRootPane.addNotify(JRootPane.java:680)
    at java.awt.Container.addNotify(Container.java:2544)
    at java.awt.Window.addNotify(Window.java:467)
    at java.awt.Frame.addNotify(Frame.java:501)
    at java.awt.Window.pack(Window.java:485)
    at org.jdesktop.application.SingleFrameApplication.initRootPaneContainer(SingleFrameApplication.java:216)
    at org.jdesktop.application.SingleFrameApplication.show(SingleFrameApplication.java:463)
    at org.openshapa.OpenSHAPA.startup(OpenSHAPA.java:444)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    ... 7 more

Why would simply using the native toolkit to create a frame (but not return it) create an exception, when it would otherwise behaves as normal when the super.createFrame is commented?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

静赏你的温柔 2024-08-20 08:47:13

我没有在 OSX 上工作过,但在 Windows 上也会出现同样的问题,原因是这样的:

当你执行 super.createFrame() 时,你本质上是在创建本机对等点,最终会尝试show 并因此调用 addNotify 方法。现在里面有很多方法直接将对等点转换为 WFramePeer(这是 Windows 的情况,OSX 可能是 CWindowPeer 或其他),因此出现 ClassCastException。在你的情况下,我的猜测是,类 CWindow 正在尝试将你的 UISpecFramePeer 转换为 WFramePeer(或 CFramePeer 或其他)。只需通过反编译检查CWindow代码即可。请不要忘记发布您的发现。

I havent worked on OSX, but the same problem would occur on Windows too and the reason would be this:

When you do super.createFrame(), you are essentially creating the native peer which ends up trying to show and hence addNotify methods are called. Now inside there are lot of methods that directly cast the peer to WFramePeer(this is incase of Windows, OSX it may be CWindowPeer or whatever), hence the ClassCastException. In your case, my guess is, the class CWindow is trying to cast your UISpecFramePeer to WFramePeer(or CFramePeer or whatever). Just check the CWindow code by decompiling and check. Please don't forget to post your findings.

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