andreasgal/j2me.js — pull request #260 by mykmelez (2014-09-15 07:19:57+00:00)
Title: handle invalid image data

At some point, a midlet I'm testing calls the *Image.createImage* constructor variant that takes an *InputStream*, but it passes it a stream that returns only a single byte. That causes *ImageDataFactory.createImmutableImageDecodeImage* to fail silently, which then causes *Graphics.render* to throw a JavaScript exception.

*ImageDataFactory.getImageDataFromStream* expects *createImmutableImageDecodeImage* to raise *IllegalArgumentException* if "data cannot be not decoded," so this branch makes it do that. It also makes *Graphics.render* check that there's native image data before trying to access it and warn if there isn't (instead of throwing a JavaScript error, to avoid halting the VM thread just because an image couldn't render).

And it stores native image data in a JS property rather than the Java *nativeImageData* field, which happens to work but shouldn't be counted on, given that it's supposed to be an integer!

@marco-c This unblocks me from working on other things, like TextEditor, and may unblock you and others as well.