FEST

invokeAndWait() in JApplet.init() causes Exception

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: FEST-Swing 1.2a3
  • Fix Version/s: FEST-Swing 1.2a4
  • Component/s: Swing
  • Labels:
    None
  • Number of attachments :
    0

Description

I have a JApplet which creates its GUI in event dispatcher thread using invokeAndWait()

public void init() {
                try {
                        SwingUtilities.invokeAndWait(new Runnable() {
                                @Override
                                public void run() {
                                        createGUI();
                                }
                        });
                }
                ...
        }

This line in setUp causes to following trace:

viewer = AppletLauncher.applet(new MyApplet()).withParameters
(parameters).start();

java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
        at org.fest.swing.edt.GuiActionRunner.rethrowCatchedExceptionIn(GuiActionRunner.java:145)
        at org.fest.swing.edt.GuiActionRunner.resultOf(GuiActionRunner.java: 126)
        at org.fest.swing.edt.GuiActionRunner.execute(GuiActionRunner.java: 73)
        at org.fest.swing.launcher.NewAppletViewerQuery.showAppletViewerWith(NewAppletViewerQuery.java:39)
        at org.fest.swing.launcher.AppletLauncher.start(AppletLauncher.java: 212)
        at ch.hsr.LAppletParameterTestCase.setUp(LAppletParameterTestCase.java:36)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
        at org.fest.swing.junit.v4_5.runner.GUITestRunner.runChild(GUITestRunner.java:67)
        at org.fest.swing.junit.v4_5.runner.GUITestRunner.runChild(GUITestRunner.java:38)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
        at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 

Activity

Hide
Kyle Murphy added a comment -

I'm also running into this exact same issue in more or less the same circumstances.

Show
Kyle Murphy added a comment - I'm also running into this exact same issue in more or less the same circumstances.
Hide
Alex Ruiz added a comment -

I just uploaded a snapshot at http://snapshots.repository.codehaus.org/org/easytesting

Please give it a try

Thanks!
-Alex

Show
Alex Ruiz added a comment - I just uploaded a snapshot at http://snapshots.repository.codehaus.org/org/easytesting Please give it a try Thanks! -Alex
Hide
Kyle Murphy added a comment -

The latest snapshot fixed the issue for me, although I do notice one difference from the previous version. Before I was able to pass AppletViewer straight into the FrameFixture constructor, but now I need to use the window() method of viewer to get the Frame instance. Not sure if FrameFixture had a constructor that accepted an AppletViewer before, or if AppletViewer subclassed JFrame or what.

Show
Kyle Murphy added a comment - The latest snapshot fixed the issue for me, although I do notice one difference from the previous version. Before I was able to pass AppletViewer straight into the FrameFixture constructor, but now I need to use the window() method of viewer to get the Frame instance. Not sure if FrameFixture had a constructor that accepted an AppletViewer before, or if AppletViewer subclassed JFrame or what.
Hide
Alex Ruiz added a comment -

Hi Kyle,

I had to make that change to make it work (probably the original design was poor.) I'll try to leave the API as it was while keeping the fix. If that's not possible the least I can do is document the change

Thanks,
-Alex

Show
Alex Ruiz added a comment - Hi Kyle, I had to make that change to make it work (probably the original design was poor.) I'll try to leave the API as it was while keeping the fix. If that's not possible the least I can do is document the change Thanks, -Alex
Hide
Alex Ruiz added a comment -

Hi Kyle,

Thanks a lot for your feedback!

I uploaded a new snapshot. AppletViewer is a JFrame again

The only change is I had to make its constructors private, and added static factory methods ("newView"). I documented the changes in the class' Javadoc.

Please give it a try

Cheers!
-Alex

Show
Alex Ruiz added a comment - Hi Kyle, Thanks a lot for your feedback! I uploaded a new snapshot. AppletViewer is a JFrame again The only change is I had to make its constructors private, and added static factory methods ("newView"). I documented the changes in the class' Javadoc. Please give it a try Cheers! -Alex
Hide
Kyle Murphy added a comment -

Just tried the latest snapshot and it seems to be working fine. I can once again add the viewer straight into a FrameFixture. I'm not sure about the static factory method as I'm using the AppletLauncher factory to construct instances of AppletViewer, but I assume it's been changed to use the new factory method internally.

Show
Kyle Murphy added a comment - Just tried the latest snapshot and it seems to be working fine. I can once again add the viewer straight into a FrameFixture. I'm not sure about the static factory method as I'm using the AppletLauncher factory to construct instances of AppletViewer, but I assume it's been changed to use the new factory method internally.
Hide
Alex Ruiz added a comment -

Awesome! Thanks Kyle

Show
Alex Ruiz added a comment - Awesome! Thanks Kyle

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: