3

I'm upgrading a GWT project from GWT 1.7.1 to currently newest version 2.0.3. It seems that new GWT broke String.split(String regex) method - I get the following error on the Javascript side:

this$static is undefined

This happens in this line of my .nocache.js file:

if (maxMatch == 0 && this$static.length > 0) {

...which happens to be a part of String split method equivalent in Javascript.

Is there a cure for this, apart from doing string splitting myself?

Domchi
  • 10,705
  • 6
  • 54
  • 64

1 Answers1

8

A possible workaround is to write a JSNI method that wraps around the standard JavaScript split function, something like this (note: code not tested :))

public static final native String[] split(String string, String separator) /*-{
    return string.split(separator);
}-*/;

The closest thing on the GWT Issues list is Issue 3071, but I'd just stick with JSNI on this one (just like I stick with JSNI for regular expressions).

Igor Klimer
  • 15,321
  • 3
  • 47
  • 57
  • 1
    Thanks! This works, with minor correction that return argument must be String[] instead of JsArrayString. – Domchi Mar 12 '10 at 14:16
  • Heh, thanks for reporting back - I've corrected the code above. I guess JSNI is not that "stupid" (JsArray* classes are usually used with JavaScript Overlay Objects, so I thought that this would be the case here too). – Igor Klimer Mar 12 '10 at 18:13
  • 1
    these seems such a weird thing to missing from the emulation library – NimChimpsky Jun 29 '17 at 04:17