poniedziałek, 12 listopada 2012

GWT WebApp and iOS 6 Safari ClassCastException problem + solution

There are many kind of troubles with new iOS 6. I meet some with Google Web Toolkit app.
With Safari 6 on OS X everything is working good. Also on the iPad with iOS 5 is well. Troubles began after upgrading to iOS 6 (10A403). The problem is ClassCastException.

It can be thrown occasionally in different places while app is initializing. For example it happens while iterating collection of String with foreach. Another time, when adding an item to the collection  using put or putAll, it means Map<String, V> passed to collection.putAll(newValues). The exception is thrown by java.util.HashMap.

The strangest thing is that connecting the iPad to Mac and running the Remote Web Inspector makes problems disappear. Also compiling application with compiler.stackMode set to emulated, hides all the problems. So I debugged it with using simple Window.alert messages.

I believe iOS 6.1 will be fixed (but for now upgrade to 6.0.1 brings no changes).

If somebody has simillar problems, there is a temporary solution. You can compile application with -XdisableCastChecking. If you use this option in your application, it might help.
This option can have a significant positive impact on performance, but it should be used in production mode only.
Unfortunatelly it's not the only problem with new iOS...