From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25024 invoked by alias); 14 May 2004 20:34:47 -0000 Mailing-List: contact java-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-prs-owner@gcc.gnu.org Received: (qmail 25012 invoked by uid 48); 14 May 2004 20:34:46 -0000 Date: Fri, 14 May 2004 20:34:00 -0000 From: "denis dot walesch at free dot fr" To: java-prs@gcc.gnu.org Message-ID: <20040514203436.15447.denis.walesch@free.fr> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug libgcj/15447] New: Lack of exception raised in ByteBufferImpl & co. X-Bugzilla-Reason: CC X-SW-Source: 2004-q2/txt/msg00102.txt.bz2 List-Id: After slicing a ByteBuffer, getting or setting values does'nt reflect this action and the exceptions promised by the interface of get/set are not raised. As i am a bad english writer because it's not my native language, you'll find following a little test case. --- cut here ------ import java.nio.ByteOrder; import java.nio.ByteBuffer; import java.nio.BufferUnderflowException; public class BufferTest { public static void dumpBytes(ByteBuffer b) { System.out.println( "dumpBytes : " ); for( int i=0; iByteBuffer object with a given capacity. */ diff -Naur nio.orig/ByteBufferImpl.java nio/ByteBufferImpl.java --- nio.orig/ByteBufferImpl.java Fri May 14 11:24:02 2004 +++ nio/ByteBufferImpl.java Fri May 14 11:42:37 2004 @@ -126,10 +126,16 @@ /** * Relative get method. Reads the next byte from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * bytes in this buffer. */ final public byte get () { - byte result = backing_buffer [position ()]; + if( remaining() > 0 ) + throw new BufferUnderflowException(); + + byte result = backing_buffer [array_offset+position ()]; position (position () + 1); return result; } @@ -138,6 +144,8 @@ * Relative put method. Writes value to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * bytes in this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ final public ByteBuffer put (byte value) @@ -145,7 +153,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [position ()] = value; + if( remaining() > 0 ) + throw new BufferOverflowException(); + + backing_buffer [array_offset+position ()] = value; position (position () + 1); return this; } @@ -159,7 +170,10 @@ */ final public byte get (int index) { - return backing_buffer [index]; + if( index < 0 || limit() < index ) + throw new IndexOutOfBoundsException(); + + return backing_buffer [array_offset+index]; } /** @@ -175,7 +189,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [index] = value; + if( index < 0 || limit() < index ) + throw new IndexOutOfBoundsException(); + + backing_buffer [array_offset+index] = value; return this; } diff -Naur nio.orig/CharBufferImpl.java nio/CharBufferImpl.java --- nio.orig/CharBufferImpl.java Fri May 14 11:24:02 2004 +++ nio/CharBufferImpl.java Fri May 14 11:42:37 2004 @@ -115,10 +115,16 @@ /** * Relative get method. Reads the next char from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * bytes in this buffer. */ final public char get () { - char result = backing_buffer [position ()]; + if( remaining() > 0 ) + throw new BufferUnderflowException(); + + char result = backing_buffer [array_offset+position ()]; position (position () + 1); return result; } @@ -127,6 +133,8 @@ * Relative put method. Writes value to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * bytes in this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ final public CharBuffer put (char value) @@ -134,7 +142,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [position ()] = value; + if( remaining() > 0 ) + throw new BufferOverflowException(); + + backing_buffer [array_offset+position ()] = value; position (position () + 1); return this; } @@ -152,7 +163,7 @@ || index >= limit ()) throw new IndexOutOfBoundsException (); - return backing_buffer [index]; + return backing_buffer [array_offset+index]; } /** @@ -172,7 +183,7 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [index] = value; + backing_buffer [array_offset+index] = value; return this; } diff -Naur nio.orig/DoubleBufferImpl.java nio/DoubleBufferImpl.java --- nio.orig/DoubleBufferImpl.java Fri May 14 11:24:02 2004 +++ nio/DoubleBufferImpl.java Fri May 14 11:42:37 2004 @@ -97,10 +97,16 @@ /** * Relative get method. Reads the next double from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * bytes in this buffer. */ final public double get () { - double result = backing_buffer [position ()]; + if( remaining() > 0 ) + throw new BufferUnderflowException(); + + double result = backing_buffer [array_offset+position ()]; position (position () + 1); return result; } @@ -109,6 +115,8 @@ * Relative put method. Writes value to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * bytes in this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ final public DoubleBuffer put (double value) @@ -116,7 +124,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [position ()] = value; + if( remaining() > 0 ) + throw new BufferOverflowException(); + + backing_buffer [array_offset+position ()] = value; position (position () + 1); return this; } @@ -130,7 +141,10 @@ */ final public double get (int index) { - return backing_buffer [index]; + if( index < 0 || limit() < index ) + throw new IndexOutOfBoundsException(); + + return backing_buffer [array_offset+index]; } /** @@ -146,7 +160,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [index] = value; + if( index < 0 || limit() < index ) + throw new IndexOutOfBoundsException(); + + backing_buffer [array_offset+index] = value; return this; } diff -Naur nio.orig/FloatBufferImpl.java nio/FloatBufferImpl.java --- nio.orig/FloatBufferImpl.java Fri May 14 11:24:02 2004 +++ nio/FloatBufferImpl.java Fri May 14 11:42:37 2004 @@ -97,10 +97,16 @@ /** * Relative get method. Reads the next float from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * bytes in this buffer. */ final public float get () { - float result = backing_buffer [position ()]; + if( remaining() > 0 ) + throw new BufferUnderflowException(); + + float result = backing_buffer [array_offset+position ()]; position (position () + 1); return result; } @@ -109,6 +115,8 @@ * Relative put method. Writes value to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * bytes in this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ final public FloatBuffer put (float value) @@ -116,7 +124,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [position ()] = value; + if( remaining() > 0 ) + throw new BufferOverflowException(); + + backing_buffer [array_offset+position ()] = value; position (position () + 1); return this; } @@ -130,7 +141,10 @@ */ final public float get (int index) { - return backing_buffer [index]; + if( index < 0 || limit() < index ) + throw new IndexOutOfBoundsException(); + + return backing_buffer [array_offset+index]; } /** @@ -146,7 +160,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [index] = value; + if( index < 0 || limit() < index ) + throw new IndexOutOfBoundsException(); + + backing_buffer [array_offset+index] = value; return this; } diff -Naur nio.orig/IntBufferImpl.java nio/IntBufferImpl.java --- nio.orig/IntBufferImpl.java Fri May 14 11:24:02 2004 +++ nio/IntBufferImpl.java Fri May 14 11:42:37 2004 @@ -97,10 +97,16 @@ /** * Relative get method. Reads the next int from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * bytes in this buffer. */ final public int get () { - int result = backing_buffer [position ()]; + if( remaining() > 0 ) + throw new BufferUnderflowException(); + + int result = backing_buffer [array_offset+position ()]; position (position () + 1); return result; } @@ -109,6 +115,8 @@ * Relative put method. Writes value to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * bytes in this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ final public IntBuffer put (int value) @@ -116,7 +124,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [position ()] = value; + if( remaining() > 0 ) + throw new BufferOverflowException(); + + backing_buffer [array_offset+position ()] = value; position (position () + 1); return this; } @@ -130,7 +141,10 @@ */ final public int get (int index) { - return backing_buffer [index]; + if( index < 0 || limit() < index ) + throw new IndexOutOfBoundsException(); + + return backing_buffer [array_offset+index]; } /** @@ -146,7 +160,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [index] = value; + if( index < 0 || limit() < index ) + throw new IndexOutOfBoundsException(); + + backing_buffer [array_offset+index] = value; return this; } diff -Naur nio.orig/LongBufferImpl.java nio/LongBufferImpl.java --- nio.orig/LongBufferImpl.java Fri May 14 11:24:02 2004 +++ nio/LongBufferImpl.java Fri May 14 11:42:37 2004 @@ -97,10 +97,16 @@ /** * Relative get method. Reads the next long from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * bytes in this buffer. */ final public long get () { - long result = backing_buffer [position ()]; + if( remaining() > 0 ) + throw new BufferUnderflowException(); + + long result = backing_buffer [array_offset+position ()]; position (position () + 1); return result; } @@ -109,6 +115,8 @@ * Relative put method. Writes value to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * bytes in this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ final public LongBuffer put (long value) @@ -116,7 +124,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [position ()] = value; + if( remaining() > 0 ) + throw new BufferOverflowException(); + + backing_buffer [array_offset+position ()] = value; position (position () + 1); return this; } @@ -130,7 +141,10 @@ */ final public long get (int index) { - return backing_buffer [index]; + if( index < 0 || limit() < index ) + throw new IndexOutOfBoundsException(); + + return backing_buffer [array_offset+index]; } /** @@ -146,7 +160,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [index] = value; + if( index < 0 || limit() < index ) + throw new IndexOutOfBoundsException(); + + backing_buffer [array_offset+index] = value; return this; } diff -Naur nio.orig/ShortBufferImpl.java nio/ShortBufferImpl.java --- nio.orig/ShortBufferImpl.java Fri May 14 11:24:02 2004 +++ nio/ShortBufferImpl.java Fri May 14 11:42:37 2004 @@ -97,10 +97,16 @@ /** * Relative get method. Reads the next short from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * bytes in this buffer. */ final public short get () { - short result = backing_buffer [position ()]; + if( remaining() > 0 ) + throw new BufferUnderflowException(); + + short result = backing_buffer [array_offset+position ()]; position (position () + 1); return result; } @@ -109,6 +115,8 @@ * Relative put method. Writes value to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * bytes in this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ final public ShortBuffer put (short value) @@ -116,7 +124,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [position ()] = value; + if( remaining() > 0 ) + throw new BufferOverflowException(); + + backing_buffer [array_offset+position ()] = value; position (position () + 1); return this; } @@ -130,7 +141,10 @@ */ final public short get (int index) { - return backing_buffer [index]; + if( index < 0 || limit() < index ) + throw new IndexOutOfBoundsException(); + + return backing_buffer [array_offset+index]; } /** @@ -146,7 +160,10 @@ if (readOnly) throw new ReadOnlyBufferException (); - backing_buffer [index] = value; + if( index < 0 || limit() < index ) + throw new IndexOutOfBoundsException(); + + backing_buffer [array_offset+index] = value; return this; } --- cut here ------ I hope this help. -- Summary: Lack of exception raised in ByteBufferImpl & co. Product: gcc Version: 3.4.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: libgcj AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: denis dot walesch at free dot fr CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15447