harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gregory Shimansky <gshiman...@gmail.com>
Subject Re: [DRLVM][JNI]GetByteArrayRegion differs from RI (was Re: Exceptions found while running servlet...)
Date Mon, 14 Aug 2006 19:01:13 GMT
On Monday 14 August 2006 20:13 Geir Magnusson Jr wrote:
> Ivan Volosyuk wrote:
> > It looks like that it is possible to get zero bytes even at the very
> > end of array. IMHO the order of boundary checks makes sense here.
>
> This is an interesting problem. The JNI spec is clear that we should
> throw an exception when one of the indexes isn't valid, and start ==
> size is arguably not valid, as Gregory points out.
>
> So I think the JNI impl is right for now (but I want to test w/ the JNI
> impl in RI....)

I've written a test [1] myself and cannot say I completely understand the 
result. With length = 0 RI 1.5 allows calling to Get<type>ArrayRegion with 
start equal to array length but throws AIOOBE if start is greater than array 
length.

I am unsure if we want to allow this compatibility and a reason to allow it. 
When length is 0 the application still gets nothing except for clear 
exception status. There is no value in allowing this call except for allowing 
software which has a bug in it to work. On the other hand allowing start == 
length to pass violates the spec IMHO.

I think it is better if software which uses this undocumented feature was 
fixed instead of introducing this workaround, so if others agree I think 
HARMONY-1156 could be closed.

[1]
public class AIOOBE {
    static {
        System.loadLibrary("AIOOBE");
    }

    private native void nativeMethod(int array[], int start);

    public static void main(String args[]) {
        int array[] = new int[10];
        System.out.println("Calling with length 10");
        (new AIOOBE()).nativeMethod(array, 10);
        System.out.println("Calling with length 11");
        (new AIOOBE()).nativeMethod(array, 11);
        System.out.println("Calling with length 100");
        (new AIOOBE()).nativeMethod(array, 100);
    }
}

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class AIOOBE */

#ifndef _Included_AIOOBE
#define _Included_AIOOBE
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     AIOOBE
 * Method:    nativeMethod
 * Signature: ([II)V
 */
JNIEXPORT void JNICALL Java_AIOOBE_nativeMethod
  (JNIEnv *jenv, jobject thisObject, jintArray array, jint start)
{
    int buffer[1024];
    (*jenv)->GetIntArrayRegion(jenv, array, start, 0, buffer);
}

#ifdef __cplusplus
}
#endif
#endif


-- 
Gregory Shimansky, Intel Middleware Products Division

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message