InternalError: Bad rare toggle magic - what does that mean?

Today I have a stacktrace with a very strange error. In fact, I may be the first to ever get this (YAY!), Since prior to posting this question, the only cases of "bad rare switch magic" on Google are in the Android source code.

Here's the stacktrace part (Android 2.3.4):

java.lang.InternalError: bad sparse switch magic


An error occurred while exiting the MyItemAdapter constructor. Since it is internal, I'm pretty sure it's not my fault, but I just would like to know what went wrong in the Dalvik VM.

This error seems to be instruction-related switch

, just for clarification - I didn't use it directly in the MyItemAdapter constructor. To figure out what went wrong I will probably have to go through a lot of dalwick related code, so I ask you - is there someone who can explain to me what went wrong? I'm just curious.


Here is the Android code snippet that is causing this error:


source to share

1 answer

There is a decrypted sparse switch dex code that points to the Android interpreter in a region of memory that is not actually a sparse switch operator.

Dex byte code can represent two types of switch statements: packed or sparse. A packed switch operation should only store the lowest value to turn on. Each subsequent switch value is incremented by one from the previous value, so the case statements store only the branch target in byte code. The sparse switch format has an entry for a single value and a branch target for a case statement. See the "sparse-payload" section in the "Bytecode for Dalvik VM" document ( ).

Rare switch statements in dex are denoted by the noop byte code command with the second byte 0x02 ( ). The first byte of the noop command is always 0x00, so the full magic signature of the sparse switch statement is 0x0200.

The dex byte code command to actually execute a sparse switch statement is called a sparse key. This code is 0x2c, and it also accepts a register to check for a switch statement and a switch table address . I believe the address of the switch table in your dex file is wrong. Without additional information, it would be difficult to say why.



All Articles