开发者

Android FileOutputStream.write: got java.io.IOException: Math result not representable

I got that "interesting" exception in my in-the-wild server errorlog. My app posts exceptions and "wtf"-errors to my central server, so I don't have much i开发者_如何学Pythonnformation what exactly happend. I just know THAT it happend, and I don't have any clue.

Stacktrace:

java.io.IOException: Math result not representable at org.apache.harmony.luni.platform.OSFileSystem.writeImpl(Native Method) at org.apache.harmony.luni.platform.OSFileSystem.write(OSFileSystem.java:129) at java.io.FileOutputStream.write(FileOutputStream.java:297) at net.jav.apps.romeolive.RomeoInterface.fetchBinaryToFile(RomeoInterface.java:299) at net.jav.apps.romeolive.HeartBeatService$_fetchPic.run(HeartBeatService.java:327) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) at java.lang.Thread.run(Thread.java:1096)

The code in place of net.jav.apps.romeolive.RomeoInterface:

    byte[] ret=fetchBinary(fullurl);

    if (ret==null) return false;

    try 
    {
        FileOutputStream os=new FileOutputStream(getCacheFileName(type,fullurl));
        os.write(ret, 0, ret.length);

The "failing" line #299 is the os.write()

fetchBinary(url) fetches some binary file (thumbnail jpg) from a web server and returns it as a byte[], or NULL if not found/error.

getCacheFileName(type,fullurl) returns the cacheDir() plus type plus the sanitized fullurl (removing slashes, only use the localpart of the url).

So what exactly fails, is... Trying to write the existing thumbnail jpg byte[] to a perfectly crafted filename in cacheDir().

The device where this exception showed up (ONCE only until now) is: GT-I9000@samsung/GT-I9000/GT-I9000/GT-I9000:2.2.1/FROYO/XXJPY:user/release-keys

Did anyone have this "Math result not representable" as IOException? I'd really like to nail down that thing ;) Google and Stackoverflow didn't show up anything helpful or even related.

Thanks a lot, Oliver


It doesn't seem to me like this could be a bug in your code, but I can't be sure of that.

The string "Math result not representable" shows up in Google searches as being associated with ERRNO 34 (ERANGE), which is also represented with the string "Numerical result out of range".

The source for org.apache.harmony.luni.platform.OSFileSystem.writeImpl is:

static jlong harmony_io_writeImpl(JNIEnv* env, jobject, jint fd,
        jbyteArray byteArray, jint offset, jint nbytes) {

    jbyte* bytes = env->GetByteArrayElements(byteArray, NULL);
    jlong result = TEMP_FAILURE_RETRY(write(fd, bytes + offset, nbytes));
    env->ReleaseByteArrayElements(byteArray, bytes, JNI_ABORT);

    if (result == -1) {
        if (errno == EAGAIN) {
            jniThrowException(env, "java/io/InterruptedIOException",
                    "Write timed out");
        } else {
            jniThrowIOException(env, errno);
        }
    }
    return result;
}

So any random system error during the write will percolate back up to Java as an IOException, including ERANGE. But I don't see where a range error could have happened; the man page for write(2) doesn't list ERANGE as one of its possible error codes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜