problems, solutions and general blabber about computers and interesting stuff.
as seen by yours truly.

April 5, 2008

How to crash a J2ME emulator (and Nokia phones)

When working on OpenWIG, the mobile phone emulator would always crash (and i mean crash hard, that's segfault for you) before running anything useful. Weird, I thought, and reinstalled NetBeans, then switched to a different JDK, then different operating system, then different WTK (not really different, though; turns out that SonyEricsson's J2ME SDK contains basically unmodified WTK from Sun). Everything would crash. I had to upload the midlet to my phone (SE K610i) for each testing cycle. That worked without problems.

But "debugging" on the phone, without debugger at the ready, is a whole lot of fun. Mainly because on the phone, you don't have backtraces.(Next time I might try OTA debugging, but right now I don't even know what exactly that is...)

The Lua VM must be triggering some bug in the emulator, I thought, too bad for me. And I released a testing version that worked perfectly on my phone.Oddly enough, the Lua VM managed to trigger a bug in Nokia phones too. They would freeze or reset when attempting to run the midlet.

Someone previously mentioned that the function System.identityHashcodecrashed for some strings such as "error"

Isn't that funny?Fortunately, the solution is simple: instead of System.identityHashcode(a), use a.hashCode().

Apparently, the identityHashcode function was slightly broken in older JVM's (and the WTK too, apparently. oh, and in Nokia phones. but oh well, i never liked Nokia anyway) and it couldn't cope with too many internalized strings.