Monday, 5 December 2011

Gwt and Blackberry OS7 don't play well together

If you ever wonder why your GWT app doesn't start on a blackberry OS7, you might be experiencing the same problem I had a week ago. I spend a couple of hours investigating and basically, if you try to perform a Integer.parseInt, it fails miserably. Nothing in the logs, nothing in the console, etc. Debugging the JS gwt code I found that it's checking on the min/max value of an int. And guess what? OS7 browser doesn't support them. That looks like a dodgy bit overflow problem... I put a little test case together on StackOverflow for you to understand the problem. Here's a copy of it:



<html>
  <body>
    test page
    <script>
          i = 0;
          if(i < -2147483647) {
             alert("very low")
          
          if(i < -2147483648) {
             alert("very very low")
          
          if(i < -2147483649) {
              alert("very very very low")
          }
     </script>
  </body>
</html>


Surprisingly, the phone comes up with the message "very very low".

So, solutions are:

  • Don't use Integer.parseInt - use Long.parseLong instead or something like that - well... that might be acceptable for some people...
  • Override the Integer class and change the parseInt method to check the value on a bit less than -2147483648 - or enforce the use of a long.
  • Hope and pray that RIM will fix it asap... and that everybody updates... 


Hope that helps.

No comments:

Post a Comment