assertj / assertj-swing

Fluent assertions for Swing apps
Other
109 stars 52 forks source link

java.lang.VerifyError: Bad type on operand stack #253

Open hansthesis2020 opened 4 years ago

hansthesis2020 commented 4 years ago

Hey,

I want to introduce click-tests to my swing-application and it seems AssertJ is the way to go ^^.

After testing and long investigations I still cant't get rid of one error and I'm very unsure it's a java-bug, a version-thing or related to the structure of the legacy-code. I would be very happy if someone could point me in the right correction :):

When I run the testcase with in @onSetUp:

ApplicationLauncher withArgs = application(MainClass.class).withArgs("args");
withArgs.start();

the test stops with

org.assertj.swing.dependency.fest_reflect.exception.ReflectionError: Unable to invoke method 'main' with arguments [['abc']]
    at org.assertj.swing.dependency.fest_reflect.method.Invoker.cannotInvokeMethod(Invoker.java:124)
    at org.assertj.swing.dependency.fest_reflect.method.Invoker.invoke(Invoker.java:116)
    at org.assertj.swing.launcher.ApplicationLauncher.start(ApplicationLauncher.java:109)
    at abc.TestClass.onSetUp(TestClass.java:114)
    at abc.AssertJSwingJUnitTestCase.setUp(AssertJSwingJUnitTestCase.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    abc/AbstractDefaultWindow.doJob(I)V @327: invokestatic
  Reason:
    Type 'abc/AbstractDefaultWindow' (current frame, stack[1]) is not assignable to 'java/awt/Component'
  Current Frame:
    bci: @327
    flags: { }
    locals: { 'abc/AbstractDefaultWindow', integer, 'java/lang/Exception' }
    stack: { 'java/lang/Exception', 'abc/AbstractDefaultWindow', 'java/lang/String' }
  Bytecode:
    0x0000000: 1b9b 0024 2ab6 0047 1bb6 00c2 04b8 00c8
    0x0000010: b900 cd02 0099 0010 2a1b b600 d02a 1bb7
    0x0000020: 00d2 a701 282a b400 8ec1 004d 9900 252a
    0x0000030: b400 8ec0 00d4 1bb9 00d7 0200 2a1b b700
    0x0000040: d22a 1b99 0007 04a7 0004 03b6 00db a700
    0x0000050: fc2a b400 8ec6 0032 2ab6 0047 b600 df12
    0x0000060: e1b6 0076 9900 231b 04a0 001e 2ab4 008e
    0x0000070: c000 65b6 00e5 9a00 112a b400 8ec0 00d4
    0x0000080: 1bb9 00d7 0200 b12a b400 8ec6 0030 2ab6
    0x0000090: 0047 b600 df12 e1b6 0076 9a00 122a b600
    0x00000a0: 47b6 00df 12e7 b600 7699 0012 1b04 a000
    0x00000b0: 0d2a b400 8ec0 0065 b600 ea2a 1bb7 00d2
    0x00000c0: 2ab4 008e c600 3f2a b600 47b6 00df 12e1
    0x00000d0: b600 7699 0030 2ab4 008e c000 d41b b900
    0x00000e0: d702 002a b400 8ec0 0065 1b9a 0007 04a7
    0x00000f0: 0004 03b6 00ed 2a1b 9900 0704 a700 0403
    0x0000100: b600 db2a b400 98c6 0043 2ab6 0047 b600
    0x0000110: df12 e1b6 0076 9900 342a b400 98c0 0078
    0x0000120: 1b9a 0007 04a7 0004 03b6 00f0 2a1b 9900
    0x0000130: 0704 a700 0403 b600 dba7 0011 4d2c 2ab2
    0x0000140: 001c 12f2 b600 72b8 00f6 b1            
  Exception Handler Table:
    bci [0, 134] => handler: 316
    bci [135, 313] => handler: 316
  Stackmap Table:
    same_frame(@37)
    same_locals_1_stack_item_frame(@74,Object[#2])
    full_frame(@75,{Object[#2],Integer},{Object[#2],Integer})
    same_frame(@81)
    same_frame(@135)
    same_frame(@172)
    same_frame(@187)
    same_locals_1_stack_item_frame(@242,Object[#101])
    full_frame(@243,{Object[#2],Integer},{Object[#101],Integer})
    same_locals_1_stack_item_frame(@255,Object[#2])
    full_frame(@256,{Object[#2],Integer},{Object[#2],Integer})
    same_frame(@259)
    same_locals_1_stack_item_frame(@296,Object[#120])
    full_frame(@297,{Object[#2],Integer},{Object[#120],Integer})
    same_locals_1_stack_item_frame(@309,Object[#2])
    full_frame(@310,{Object[#2],Integer},{Object[#2],Integer})
    same_locals_1_stack_item_frame(@316,Object[#190])
    same_frame(@330)
...
    at abc.MainClass.main(MainClass.java:142)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.assertj.swing.dependency.fest_reflect.method.Invoker.invoke(Invoker.java:112)
    ... 29 more

Class-structure is:

DefaultWindow (gets created - then the error occurs) - extends
AbstractDefaultWindow extends 
AbstractWindow extends JFrame, 
implements IStatusMessageListener, ActionListener, ChangeListener, Observer

As it's a legacy-project - I inserted

assertj-core-3.17.2.jar assertj-swing-junit-3.9.2.jar

by hand. Can this cause such a error? I also tried to build my own all-containing-dependency-jar with

<dependencies>
<dependency>
  <groupId>org.assertj</groupId>
  <artifactId>assertj-swing-junit</artifactId>
  <version>3.9.2</version>
</dependency>
</dependencies>

<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>    
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build>

but it didn't help.

Would be very glad if someone could help me :)

Kind Regards

croesch commented 4 years ago

Hi @hansthesis2020

AssertJ Swing 3.17.0 is the way to go with AssertJ Core 3.17.x. But I think it doesn't change the behavior.

Best regards

hansthesis2020 commented 4 years ago

THanks for the input - I double-checked java/compiler-versions, commented out some line of code and now I'm getting further :). I will write again when I get solution and report it