Problem
I had the following catch statement which was a problem:
} catch (DataException | JSONException exception) {
throw new RuntimeException(exception);
}
I was seeing the following exception / error in the logs:
WARN annotation.ExceptionHandlerExceptionResolver: Resolved [org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.VerifyError: Stack map does not match the one at exception handler 93 Exception Details: Location:
my/code/aspose/AsposeDataSourceBuilder.getDataSource(Ljava/lang/Object;)Lcom/aspose/words/net/System/Data/DataSet; @93: astore_1
Reason:
Type 'org/json/JSONException' (current frame, stack[0]) is not assignable to 'java/lang/RuntimeException' (stack map, stack[0])
Current Frame:
bci: @0
flags: { }
locals: { 'java/lang/Object' }
stack: { 'org/json/JSONException' }
Stackmap Frame:
bci: @93
flags: { }
locals: { 'java/lang/Object' }
stack: { 'java/lang/RuntimeException' }
Bytecode:
0x0000000: bb00 0259 b700 03b6 0004 b600 054c 2b2a
0x0000010: b600 064d bb00 0759 2cb7 0008 4ebb 0009
0x0000020: 59b7 000a 120b b600 0c2d b800 0db6 000c
0x0000030: 120e b600 0cb6 000f 3a04 bb00 1059 1211
0x0000040: b700 123a 0519 05bb 0013 5919 04b2 0014
0x0000050: b600 15b7 0016 b600 1757 1905 b04c bb00
0x0000060: 1a59 2bb7 001b bf
Exception Handler Table:
bci [0, 92] => handler: 93
bci [0, 92] => handler: 93
Stackmap Table:
same_locals_1_stack_item_extended(@93,Object[#67])
I ran across the following Github issue/commits where they split a single catch into multiple ones - and this seemed to fix the error.
https://github.com/Wikidata/Wikidata-Toolkit/commit/0d214bb8870c29c0b688db4fda71ce8a64b4a46e
https://github.com/Wikidata/Wikidata-Toolkit/issues/58
So I split the catch statement and now it also works for me:
} catch (DataException e1) {
throw new RuntimeException(e1);
}catch(JSONException e2){
throw new RuntimeException(e2);
}
Update
In case it helps, here are the two inheritence trees from the two exception types:
Question
Why does splitting the catch statement solve the error?
There's a similar question by MatKuhr here ... but I don't understand the problem/solution yet.