On 17 March 2011 19:52, Pekka Enberg <penb...@kernel.org> wrote:
> JavaDocs clearly state that ByteBuffer.allocateDirect() must throw
> IllegalArgumentException if capacity is negative.
>
> 2011-03-17  Pekka Enberg  <penb...@kernel.org>
>
>        * native/jni/java-nio/java_nio_VMDirectByteBuffer.c:
>        (Java_java_nio_VMDirectByteBuffer_allocate): Check for negative
>        capacity.
>
> ---
>  native/jni/java-nio/java_nio_VMDirectByteBuffer.c |    7 +++++++
>  1 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/native/jni/java-nio/java_nio_VMDirectByteBuffer.c 
> b/native/jni/java-nio/java_nio_VMDirectByteBuffer.c
> index bfee7e9..7325c5b 100644
> --- a/native/jni/java-nio/java_nio_VMDirectByteBuffer.c
> +++ b/native/jni/java-nio/java_nio_VMDirectByteBuffer.c
> @@ -51,6 +51,13 @@ Java_java_nio_VMDirectByteBuffer_allocate
>  {
>   void *buffer;
>
> +  if (capacity < 0)
> +    {
> +      JCL_ThrowException (env, "java/lang/IllegalArgumentException",
> +                         "negative capacity");
> +      return 0;
> +    }
> +
>   buffer = malloc (capacity);
>
>   if (buffer == NULL)
> --
> 1.7.1
>
>
>

Maybe it would be better to do this in DirectByteBufferImpl.java ?
-- 
Andrew :-)

Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net

PGP Key: F5862A37 (https://keys.indymedia.org/)
Fingerprint = EA30 D855 D50F 90CD F54D  0698 0713 C3ED F586 2A37

Reply via email to