Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powermock cannot handle collapsed catch blocks (introduced in Java 7) #505

Open
johanhaleby opened this issue Jul 25, 2015 · 6 comments
Open

Comments

@johanhaleby
Copy link
Collaborator

From ger...@gmail.com on March 06, 2014 09:12:28

What steps will reproduce the problem? 1. Surround a method, which throws multiple checked exceptions, with a try catch block
2. Collapse all exceptions in 1 line of code. For example, when using reflection to call a method, it will throw several checked exceptions, like this:

try {
Class<? extends ControlledVocabulary> entityClass = findControlledVocabularyFor(request.getType()).getEntityClass();
builder = (ControlledVocabulary.Builder) entityClass.getDeclaredMethod("builder").invoke(null);
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
LOGGER.error(TAG, "Could not instantiate ControlledVocabulary of type " + request.getType(), e);
throw new RuntimeException("Could not instantiate ControlledVocabulary of type " + request.getType(), e);
}

(ignore the business rules behind this, let's just say that I'm getting some class, based on a string in the request, and I am calling a (static) method to get a builder object from that class)

  1. Write a unit test for this class using PowerMock. For testing reasons, I had to mock a constructor used by that class. So, annotated on the type are these annotations:

@RunWith(PowerMockRunner.class)
@PrepareForTest(ManageControlledVocabularyService.class)

... where, evidently, ManageControlledVocabularyService is the class which I'm testing.

############################ What is the expected output? What do you see instead? I would expect PowerMock not to complain :-)

Instead, I get a java.lang.VerifyError:


<<>>

java.lang.VerifyError: Stack map does not match the one at exception handler 314
Exception Details:
Location:
be/inbo/lifewatch/seabirds/manage/controlled_vocabulary/service/ManageControlledVocabularyService.createControlledVocabulary(Lbe/inbo/lifewatch/seabirds/manage/controlled_vocabulary/controller/request/ManageControlledVocabularyRequest;)Lbe/inbo/lifewatch/seabirds/manage/controlled_vocabulary/model/ControlledVocabulary; @314: astore_3
Reason:
Type 'java/lang/IllegalAccessException' (current frame, stack[0]) is not assignable to 'java/lang/NoSuchMethodException' (stack map, stack[0])
Current Frame:
bci: @87
flags: { }
locals: { 'be/inbo/lifewatch/seabirds/manage/controlled_vocabulary/service/ManageControlledVocabularyService', 'be/inbo/lifewatch/seabirds/manage/controlled_vocabulary/controller/request/ManageControlledVocabularyRequest' }
stack: { 'java/lang/IllegalAccessException' }
Stackmap Frame:
bci: @314
flags: { }
locals: { 'be/inbo/lifewatch/seabirds/manage/controlled_vocabulary/service/ManageControlledVocabularyService', 'be/inbo/lifewatch/seabirds/manage/controlled_vocabulary/controller/request/ManageControlledVocabularyRequest' }
stack: { 'java/lang/NoSuchMethodException' }
Bytecode:
0000000: 2a13 0208 04bd 003f 5903 2b53 1302 09b8
0000010: 01d4 1302 0bb8 01dc 4d2c 013a 0401 3a05
0000020: 1904 1303 60b8 035a 1303 6113 0362 b803
0000030: 64b8 0356 3a06 1906 b203 30a6 000b b201
0000040: e03a 05a7 000a 1906 c002 2d3a 0519 05a5
0000050: 0008 2cc0 020c b02a 2bb9 003a 0100 b700
0000060: 04b6 003b 4e2d 123c 03bd 003d 3a06 3a05
0000070: 3a04 013a 0701 3a08 1904 01a5 000a 1904
0000080: 3a08 a700 0b13 0366 b803 683a 0819 0813
0000090: 0369 05bd 003f 5903 1905 5359 0419 0653
00000a0: 1303 6ab8 036b 1303 6db8 0347 3a09 1909
00000b0: b203 30a6 0011 1904 1905 1906 b603 6f3a
00000c0: 07a7 000a 1909 c003 703a 0719 0701 03bd
00000d0: 003f 3a06 3a05 3a04 013a 0701 3a08 1904
00000e0: 01a5 000a 1904 3a08 a700 0b13 0371 b803
00000f0: 683a 0819 0813 0372 05bd 003f 5903 1905
0000100: 5359 0419 0653 1303 73b8 036b 1303 74b8
0000110: 0347 3a09 1909 b203 30a6 0011 1904 1905
0000120: 1906 b603 763a 07a7 000a 1909 c002 2d3a
0000130: 0719 07c0 0041 4da7 0389 4e01 3a04 013a
0000140: 0519 0413 0377 b803 6813 0378 1303 79b8
0000150: 037b b803 7c3a 0619 06b2 0330 a600 0bb2
0000160: 0045 3a05 a700 0a19 06c0 037d 3a05 1905
0000170: 1246 0000 0000 013a 0401 3a05 1303 7fb8
0000180: 037b 03bd 003f 1303 81b8 036b b803 833a
0000190: 0619 06b2 0330 a500 3319 06c1 0266 9900
00001a0: 21b8 0385 1303 86b8 0387 123f 01b6 0389
00001b0: b603 8a01 b603 8cc0 0047 3a05 a700 0a19
00001c0: 06c0 0047 3a05 a700 0cbb 0047 59b7 038e
00001d0: 3a05 1905 1249 3a05 3a04 013a 0601 3a07
00001e0: 1904 01a5 000a 1904 3a07 a700 0b13 0390
00001f0: b803 923a 0719 0713 0393 04bd 003f 5903
0000200: 1905 5313 0394 b803 9513 0396 b803 983a
0000210: 0819 08b2 0330 a600 0f19 0419 05b6 039a
0000220: 3a06 a700 0a19 08c0 039b 3a06 1906 2bb9
0000230: 003a 0100 3a05 3a04 013a 0601 3a07 1904
0000240: 01a5 000a 1904 3a07 a700 0b13 039c b803
0000250: 923a 0719 0713 039d 04bd 003f 5903 1905
0000260: 5313 039e b803 9513 039f b803 a03a 0819
0000270: 08b2 0330 a600 0f19 0419 05b6 03a1 3a06
0000280: a700 0a19 08c0 039b 3a06 1906 3a04 013a
0000290: 0501 3a06 1904 01a5 000a 1904 3a06 a700
00002a0: 0b13 03a2 b803 923a 0619 0613 03a3 03bd
00002b0: 003f 1303 a4b8 0395 1303 a6b8 03a7 3a07
00002c0: 1907 b203 30a6 000d 1904 b603 a93a 05a7
00002d0: 000a 1907 c003 aa3a 0519 052d b900 4c04
00002e0: 0000 0000 0000 0000 0001 3a04 013a 0513
00002f0: 03ab b803 ad03 bd00 3f13 03ae b803 95b8
0000300: 03af 3a06 1906 b203 30a5 0033 1906 c102
0000310: 6699 0021 b803 b013 03b1 b803 b312 3f01
0000320: b603 b4b6 03b5 01b6 038c c000 473a 05a7
0000330: 000a 1906 c000 473a 05a7 000c bb00 4759
0000340: b703 b73a 0519 0512 493a 053a 0401 3a06
0000350: 013a 0719 0401 a500 0a19 043a 07a7 000b
0000360: 1303 b8b8 03ba 3a07 1907 1303 bb04 bd00
0000370: 3f59 0319 0553 1303 bcb8 0395 1303 bdb8
0000380: 03bf 3a08 1908 b203 30a6 000f 1904 1905
0000390: b603 c03a 06a7 000a 1908 c003 9b3a 0619
00003a0: 062b b900 3a01 003a 053a 0401 3a06 013a
00003b0: 0719 0401 a500 0a19 043a 07a7 000b 1303
00003c0: c1b8 03ba 3a07 1907 1303 c204 bd00 3f59
00003d0: 0319 0553 1303 c3b8 0395 1303 c4b8 03bf
00003e0: 3a08 1908 b203 30a6 000f 1904 1905 b603
00003f0: c03a 06a7 000a 1908 c003 9b3a 0619 063a
0000400: 0401 3a05 013a 0619 0401 a500 0a19 043a
0000410: 06a7 000b 1303 c5b8 03ba 3a06 1906 1303
0000420: c603 bd00 3f13 03c7 b803 9513 03c8 b803
0000430: bf3a 0719 07b2 0330 a600 0d19 04b6 03c9
0000440: 3a05 a700 0a19 07c0 03aa 3a05 1905 2d3a
0000450: 063a 0501 3a04 013a 0713 03cb b803 cd05
0000460: bd00 3f59 0319 0553 5904 1906 5313 03cf
0000470: b803 95b8 03d1 3a08 1908 b203 30a5 0033
0000480: 1908 c102 6699 0021 b803 d213 03d3 b803
0000490: cd12 3f01 b603 d5b6 03d6 01b6 038c c000
00004a0: 4d3a 07a7 000a 1908...

Original issue: http://code.google.com/p/powermock/issues/detail?id=485

@johanhaleby
Copy link
Collaborator Author

From bupadh...@noknok.com on February 08, 2015 23:22:41

is this issue fixed in latest version of PwerMock?

@johanhaleby
Copy link
Collaborator Author

From geroen.j...@gtempaccount.com on February 10, 2015 08:48:00

Haven't retried, but I don't think so, given the status of the ticket ...

@johanhaleby
Copy link
Collaborator Author

From pattymna...@gmail.com on February 10, 2015 08:52:27

I saw this issue disappear after updating to javassist-3.19.0 (along with powermock-easymock-1.6.0).

@johanhaleby
Copy link
Collaborator Author

From bupadh...@noknok.com on February 11, 2015 05:06:09

@pattymna : many thanks for your reply. Updating to javassist-3.19.0 really worked

@johanhaleby
Copy link
Collaborator Author

From pattymna...@gmail.com on February 11, 2015 05:11:43

Glad to hear it :)

@johanhaleby
Copy link
Collaborator Author

From alexey.v...@gmail.com on July 21, 2015 05:37:33

Still didn't work for me even with javassist-3.19.0 and powermock 1.6.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant