dotxyteam / SwingTestingToolkit

Java-Swing GUI testing framework
8 stars 0 forks source link

Reports can't be loaded #2

Open PizzAXA opened 3 months ago

PizzAXA commented 3 months ago

Hi, first of all thanks for the great tool - I'm already enjoying it a lot. Today I came across a little issue though: In the editor, you can't load existing reports. When selecting an existing report directory (suggestion for the future: I think it would be more intuitive if I could select the report file instead of the folder), the following error will show up:

Forbidden Class Error: xy.ui.testing.TestReport
    at xy.reflect.ui.control.swing.renderer.SwingRenderer.showBusyDialogWhile(SwingRenderer.java:1136)
    at xy.reflect.ui.control.swing.util.SwingRendererUtils.showBusyDialogWhileInvokingMethod(SwingRendererUtils.java:679)
    at xy.reflect.ui.control.swing.MethodAction$2.invoke(MethodAction.java:230)
    at xy.reflect.ui.util.ReflectionUIUtils.invokeMethodThroughModificationStack(ReflectionUIUtils.java:749)
    at xy.reflect.ui.control.swing.MethodAction$1.invoke(MethodAction.java:175)
    at xy.reflect.ui.control.swing.MethodAction.invokeAndSetReturnValue(MethodAction.java:243)
    at xy.reflect.ui.control.swing.MethodAction.onInvocationRequest(MethodAction.java:103)
    at xy.reflect.ui.control.swing.menu.MethodActionMenuItem$1.actionPerformed(MethodActionMenuItem.java:109)
    at java.desktop/javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at java.desktop/javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at java.desktop/javax.swing.AbstractButton.doClick(Unknown Source)
    at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
    at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
    at java.desktop/java.awt.Component.processMouseEvent(Unknown Source)
    at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.desktop/java.awt.Component.processEvent(Unknown Source)
    at java.desktop/java.awt.Container.processEvent(Unknown Source)
    at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
    at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Unknown Source)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
    at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Unknown Source)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)
Caused by: Forbidden Class Error: xy.ui.testing.TestReport
    at xy.reflect.ui.info.method.DefaultMethodInfo.invoke(DefaultMethodInfo.java:194)
    at xy.reflect.ui.info.type.factory.InfoProxyFactory.invoke(InfoProxyFactory.java:410)
    at xy.reflect.ui.info.type.factory.InfoProxyFactory$GeneratedMethodInfoProxy.invoke(InfoProxyFactory.java:1834)
    at xy.reflect.ui.info.type.factory.InfoProxyFactory.invoke(InfoProxyFactory.java:410)
    at xy.ui.testing.editor.TestEditor$TestEditorReflectionUI$StandardProxyFactory.invoke(TestEditor.java:1175)
    at xy.reflect.ui.info.type.factory.InfoProxyFactory$GeneratedMethodInfoProxy.invoke(InfoProxyFactory.java:1834)
    at xy.reflect.ui.info.type.factory.InfoProxyFactory.invoke(InfoProxyFactory.java:410)
    at xy.reflect.ui.info.type.factory.InfoProxyFactory$GeneratedMethodInfoProxy.invoke(InfoProxyFactory.java:1834)
    at xy.reflect.ui.info.method.MethodInfoProxy.invoke(MethodInfoProxy.java:84)
    at xy.reflect.ui.info.method.MethodInfoProxy.invoke(MethodInfoProxy.java:84)
    at xy.reflect.ui.info.method.MethodInfoProxy.invoke(MethodInfoProxy.java:84)
    at xy.reflect.ui.info.type.factory.InfoProxyFactory.invoke(InfoProxyFactory.java:410)
    at xy.reflect.ui.info.type.factory.InfoProxyFactory$GeneratedMethodInfoProxy.invoke(InfoProxyFactory.java:1834)
    at xy.reflect.ui.control.AbstractMethodControlData.invoke(AbstractMethodControlData.java:165)
    at xy.reflect.ui.control.swing.util.SwingRendererUtils$4.run(SwingRendererUtils.java:681)
    at xy.reflect.ui.control.swing.renderer.SwingRenderer$9.run(SwingRenderer.java:1063)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
Caused by: com.thoughtworks.xstream.security.ForbiddenClassException: xy.ui.testing.TestReport
    at com.thoughtworks.xstream.security.NoTypePermission.allows(NoTypePermission.java:26)
    at com.thoughtworks.xstream.mapper.SecurityMapper.realClass(SecurityMapper.java:74)
    at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
    at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:47)
    at com.thoughtworks.xstream.core.util.HierarchicalStreams.readClassType(HierarchicalStreams.java:29)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:135)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1464)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1441)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1321)
    at xy.ui.testing.TestReport.loadFromStream(TestReport.java:237)
    at xy.ui.testing.TestReport.load(TestReport.java:204)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at xy.reflect.ui.info.method.DefaultMethodInfo.invoke(DefaultMethodInfo.java:188)
    ... 20 more

The reason is that you don't configure any permissions for XStream in the TestReport class:

    protected XStream getXStream() {
        XStream result = new XStream();
        return result;
    }

In comparison, the Tester class configures the XStream:

    protected XStream getXStream() {
        XStream result = new XStream();
        result.registerConverter(new JavaBeanConverter(result.getMapper()), -20);
        result.addPermission(AnyTypePermission.ANY);
        return result;
    }

Simply adding the line result.addPermission(AnyTypePermission.ANY); in TestReport fixes the issue.

Not sure if it's relevant, but I'm running Java 17 (32bit).

dotxyteam commented 3 months ago

Thank you for reporting the issue. It is taken into account.