public inbox for java-prs@sourceware.org help / color / mirror / Atom feed
From: "denis dot walesch at free dot fr" <gcc-bugzilla@gcc.gnu.org> To: java-prs@gcc.gnu.org Subject: [Bug libgcj/15447] New: Lack of exception raised in ByteBufferImpl & co. Date: Fri, 14 May 2004 20:34:00 -0000 [thread overview] Message-ID: <20040514203436.15447.denis.walesch@free.fr> (raw) 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; i<b.limit(); i++ ) { System.out.println( "byte #" + i + " = " + Integer.toHexString( b.get(i) ) ); } } public static void main(String args[]) { byte a[] = new byte[32]; for( int i=0; i<32; i++ ) a[i] = (byte)i; ByteBuffer b = ByteBuffer.wrap(a, 3, 5).slice(); System.out.println( "wrap()" ); dumpBytes(b.wrap(a, 3, 5)); System.out.println( "b.position() = "+b.position() ); System.out.println( "b.limit() = "+b.limit() ); dumpBytes(b.slice()); try { while(true) { System.out.println( "get(position()) = " + b.get() ); } } catch( BufferUnderflowException bue ) { System.out.println( "Ok vide !!!" ); } } } --- cut here ------ I can't access to cvs where i work to get the latest release and my home internet access is rather slow to a so big thing as gcc. But browsing the latest snapshot via cvsweb, i see that the access to values after slice has been corrected but not the exception that may be raised. Following, you'll find a patch of nio package of gcc 3.4.0 that both correct the access of the underlying buffer (now corrected) and the exception that must be raised. --- cut here ------ diff -Naur nio.orig/ByteBuffer.java nio/ByteBuffer.java --- nio.orig/ByteBuffer.java Fri May 14 11:24:02 2004 +++ nio/ByteBuffer.java Fri May 14 11:44:59 2004 @@ -65,11 +65,12 @@ /** * Allocates a new direct byte buffer. */ + public static ByteBuffer allocateDirect (int capacity) { return DirectByteBufferImpl.allocate (capacity); } - + /** * Allocates a new <code>ByteBuffer</code> 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 <code>byte</code> from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * <code>bytes</code> 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 <code>value</code> to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * <code>bytes</code> 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 <code>char</code> from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * <code>bytes</code> 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 <code>value</code> to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * <code>bytes</code> 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 <code>double</code> from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * <code>bytes</code> 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 <code>value</code> to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * <code>bytes</code> 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 <code>float</code> from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * <code>bytes</code> 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 <code>value</code> to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * <code>bytes</code> 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 <code>int</code> from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * <code>bytes</code> 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 <code>value</code> to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * <code>bytes</code> 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 <code>long</code> from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * <code>bytes</code> 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 <code>value</code> to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * <code>bytes</code> 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 <code>short</code> from the buffer. + * + * @exception BufferUnderflowException If there are no remaining + * <code>bytes</code> 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 <code>value</code> to the next position * in the buffer. * + * @exception BufferOverflowException If there no remaining + * <code>bytes</code> 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
next reply other threads:[~2004-05-14 20:34 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2004-05-14 20:34 denis dot walesch at free dot fr [this message] 2004-05-14 21:07 ` [Bug libgcj/15447] " pinskia at gcc dot gnu dot org 2004-08-14 6:57 ` pinskia at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20040514203436.15447.denis.walesch@free.fr \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=java-prs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).