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

Bad exception in the copying loop

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P1
    • Resolution: Fixed
    • Affects Version/s: 1.4.1, 1.4.2
    • Fix Version/s: 1.4.0_04
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      04
    • CPU:
      generic, sparc
    • OS:
      solaris_2.6, solaris_7

      Backports

        Description

        The 1.4.2 server VM throws a bad ArrayIndexOutOfBoundsException in the copying loop (similar to the previously fixed problem - 4629512 ).

        The test case below exits because of the ArrayIndexOutOfBoundsException inside the copying loop on 32 bit solaris in the server mode. Same test case runs correctly (without exiting) with the client compiler. The problem didn't exist in 1.3.1 and 1.2.2

        public class ReadTest {

                private Buffer _current;
                private final int BYTE_SIZE = 1;
                private int _offsetInChunk;

                public static void main(String[] args) {
                        final String _data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
                        Buffer in = new Buffer(_data);
                        ReadTest test = new ReadTest(in);
                        char[] value = new char[10];
                        int offset = 0;
                        int length = 10;
                        while (true) {
                                for(int i=0; i<6; i++) {
                                        test.testMethod(value, offset, length);
                                        System.out.println(value);
                                }
                                Buffer in2 = new Buffer(_data);
                                in.next = in2;
                                in = in2;
                        }
                }

                private ReadTest(Buffer buffer) {
                        _current = buffer;
                }

                private void testMethod(char[] value, int offset, int length) {

                        if((value == null) || (value.length-offset < length)) {
                                System.out.println("### ERROR1 ###");
                                return;
                        }

                        int inLengthInBytes = length * BYTE_SIZE;
                        int numBytesToCopy = 0;

                        while(inLengthInBytes > 0) {
                                if (_offsetInChunk >= _current.dataEndOffset) {
                                        _offsetInChunk -= _current.dataEndOffset;
                                        if(_current.next == null) {
                                                System.out.println("### ERROR2 ###");
                                                return;
                                        }
                                        _current = _current.next;
                                        _offsetInChunk += _current.dataStartOffset;
                                }

                                numBytesToCopy = _current.dataEndOffset - _offsetInChunk;
                                if (inLengthInBytes < numBytesToCopy) {
                                        numBytesToCopy = inLengthInBytes;
                                }

                                int i = 0, max = 0;
                                try {
                                        for(i = offset, max = numBytesToCopy; max > 0; i++, max -= BYTE_SIZE) {
                                                value[i] = (char)(_current.data[_offsetInChunk++] & 0xff);
                                                if (value[i] == 0) {
                                                        System.out.println("### ERROR3 ###");
                                                        return;
                                                }
                                        }
                                } catch(ArrayIndexOutOfBoundsException aioobe) {
                                        System.out.println("+++++++++++++++++++++++++++++");
                                        System.out.println(" value = " + new String(value));
                                        System.out.println(" value's length = " + value.length);
                                        System.out.println(" value's i = " + i);
                                        System.out.println(" max = " + max);
                                        System.out.println(" numBytesToCopy = " + numBytesToCopy);
                                        System.out.println(" BYTE_SIZE = " + BYTE_SIZE);
                                        System.out.println(" offset = " + offset);
                                        System.out.println("+++++++++++++++++++++++++++++");
                                        System.exit(1);
                                }
                                inLengthInBytes -= numBytesToCopy;
                                offset += numBytesToCopy / BYTE_SIZE;
                        }
                }

        }

        class Buffer {

                public byte[] data;
                public int dataStartOffset;
                public int dataEndOffset;
                public Buffer next;

                public Buffer(String _data) {
                        int chunkSize = dataEndOffset = _data.length();
                        data = _data.getBytes();
                }
        }

        Output:

        bash-2.00$ /java/re/jdk/1.4.2/promoted/latest/binaries/solaris-sparc/bin/java_g -XX:CompileOnly=ReadTest.testMethod -server ReadTest
        VM option 'CompileOnly=ReadTest.testMethod'
        ABCDEFGHIJ
        KLMNOPQRST
        ..........
        +++++++++++++++++++++++++++++
         value = 34567890AB
         value's length = 10
         value's i = 10
         max = 0
         numBytesToCopy = 2
         BYTE_SIZE = 1
         offset = 8
        +++++++++++++++++++++++++++++

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  busersunw Btplusnull User (Inactive)
                  Reporter:
                  ksoshals Kirill Soshalskiy (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: