An invalid or illegal string was specified” Exception in GWT

While work­ing with can­vas (draw­ing stuff on it) in GWT, sud­den­ly and in a seem­ing­ly unpre­dictable man­ner I got fol­low­ing error mes­sage now and then from with­in the GWT frame­work code:

com.google.gwt.core.client.JavaScriptException: (NS_ERROR_DOM_SYNTAX_ERR): An invalid or illegal string was specified;

Again, GWT tricked me into think­ing I am writ­ing Java code and made me for­get about that it is going to be com­piled into Javascript. And because of the lat­ter, a divi­sion by zero does not throw an Devi­sion­ByZe­roEx­cep­tion, no, it returns NaN even for native data types (there is no dif­fer­en­ti­a­tion between dou­ble and Dou­ble in Javascript — there is only the object-ver­sion of dou­ble, which can be of val­ue Double.NaN).

But also GWT was not pre­pared to han­dle Double.NaN. When call­ing canvas.getContext().drawImage(image,x,y) and one of x and y or both were Double.NaN I got the error mes­sage shown above. If you got the same… you know what to do now: check all devi­sions in your code for poten­tial devi­sions by zero!!

Leave a Reply

Your email address will not be published. Required fields are marked *