Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7190219

(bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 8
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Introduced In Version:
    • Resolved In Build:
      b55
    • CPU:
      x86
    • OS:
      linux
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :


        ADDITIONAL OS VERSION INFORMATION :
        Linux 3.2.0-27-generic-pae #43-Ubuntu SMP i686 i686 i386 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        In CharBuffer.put(String,int,int), if the requested space is not enough the BufferOverflowException will be thrown and the CharBuffer will be left unchanged, but actually CharBuffer's position get modified even after BufferOverflowException.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the attached test case.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Quiet exit.
        ACTUAL -
        Exceptions.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Exception in thread "main" java.lang.Exception: Buffer position should not changed!
        at CharBufferPutTest.run(CharBufferPutTest.java:57)
        at CharBufferPutTest.main(CharBufferPutTest.java:63)

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        /*
         * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
         *
         * This code is free software; you can redistribute it and/or modify it
         * under the terms of the GNU General Public License version 2 only, as
         * published by the Free Software Foundation.
         *
         * This code is distributed in the hope that it will be useful, but WITHOUT
         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
         * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
         * version 2 for more details (a copy is included in the LICENSE file that
         * accompanied this code).
         *
         * You should have received a copy of the GNU General Public License version
         * 2 along with this work; if not, write to the Free Software Foundation,
         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
         *
         * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
         * or visit www.oracle.com if you need additional information or have any
         * questions.
         */

        /*
         * Portions Copyright (c) 2012 IBM Corporation
         */

        /* @test
         * @summanry CharBuffer.put(String, int, int) changes position after exception
         * @bug
         */

        import java.nio.BufferOverflowException;
        import java.nio.CharBuffer;

        public class CharBufferPutTest {

            CharBuffer buf;

            public CharBufferPutTest () {
                char[] chars = "123456789a".toCharArray();
                buf = CharBuffer.wrap(chars);
            }

            public void run() throws Exception {
                buf.clear();

                try {
                    buf.put(String.valueOf(new char[buf.capacity() + 1]), 0,
                            buf.capacity() + 1);
                    throw new Exception("Should throw BufferOverflowException");
                } catch (BufferOverflowException e) {
                    // ignore
                }

                if (0 != buf.position()) {
                    throw new Exception("Buffer position should not changed!");
                }
            }

            public static void main(String[] args) throws Exception {
                CharBufferPutTest test = new CharBufferPutTest();
                test.run();
            }
        }

        ---------- END SOURCE ----------

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  alanb Alan Bateman
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: