< prev index next >

src/java.base/share/classes/java/lang/String.java

Print this page

        

*** 1062,1071 **** --- 1062,1072 ---- } } else { if (!isLatin1()) { // utf16 str and latin1 abs can never be "equal" return false; } + checkOffset(len, v2.length >> 1); for (int i = 0; i < len; i++) { if ((char)(v1[i] & 0xff) != StringUTF16.getChar(v2, i)) { return false; } }
*** 1732,1741 **** --- 1733,1745 ---- fromIndex = 0; } if (tgtCount == 0) { return fromIndex; } + if (tgtCount > srcCount) { + return -1; + } if (srcCoder == tgtCoder) { return srcCoder == LATIN1 ? StringLatin1.indexOf(src, srcCount, tgt, tgtCount, fromIndex) : StringUTF16.indexOf(src, srcCount, tgt, tgtCount, fromIndex); }
*** 1792,1802 **** * is the string being searched for. * * @param src the characters being searched. * @param srcCoder coder handles the mapping between bytes/chars * @param srcCount count of the source string. ! * @param tgt the characters being searched for. * @param fromIndex the index to begin searching from. */ static int lastIndexOf(byte[] src, byte srcCoder, int srcCount, String tgtStr, int fromIndex) { byte[] tgt = tgtStr.value; --- 1796,1806 ---- * is the string being searched for. * * @param src the characters being searched. * @param srcCoder coder handles the mapping between bytes/chars * @param srcCount count of the source string. ! * @param tgtStr the characters being searched for. * @param fromIndex the index to begin searching from. */ static int lastIndexOf(byte[] src, byte srcCoder, int srcCount, String tgtStr, int fromIndex) { byte[] tgt = tgtStr.value;
*** 1805,1820 **** /* * Check arguments; return immediately where possible. For * consistency, don't check for null str. */ int rightIndex = srcCount - tgtCount; - if (fromIndex < 0) { - return -1; - } if (fromIndex > rightIndex) { fromIndex = rightIndex; } /* Empty string always matches. */ if (tgtCount == 0) { return fromIndex; } if (srcCoder == tgtCoder) { --- 1809,1824 ---- /* * Check arguments; return immediately where possible. For * consistency, don't check for null str. */ int rightIndex = srcCount - tgtCount; if (fromIndex > rightIndex) { fromIndex = rightIndex; } + if (fromIndex < 0) { + return -1; + } /* Empty string always matches. */ if (tgtCount == 0) { return fromIndex; } if (srcCoder == tgtCoder) {
*** 3078,3088 **** * StringIndexOutOfBoundsException if {@code index} is * negative or greater than or equal to {@code length}. */ static void checkIndex(int index, int length) { if (index < 0 || index >= length) { ! throw new StringIndexOutOfBoundsException("index " + index); } } /* * StringIndexOutOfBoundsException if {@code offset} --- 3082,3093 ---- * StringIndexOutOfBoundsException if {@code index} is * negative or greater than or equal to {@code length}. */ static void checkIndex(int index, int length) { if (index < 0 || index >= length) { ! throw new StringIndexOutOfBoundsException("index " + index + ! ", length " + length); } } /* * StringIndexOutOfBoundsException if {@code offset}
*** 3116,3126 **** * * @throws StringIndexOutOfBoundsException * If {@code begin} is negative, {@code begin} is greater than * {@code end}, or {@code end} is greater than {@code length}. */ ! private static void checkBoundsBeginEnd(int begin, int end, int length) { if (begin < 0 || begin > end || end > length) { throw new StringIndexOutOfBoundsException( "begin " + begin + ", end " + end + ", length " + length); } } --- 3121,3131 ---- * * @throws StringIndexOutOfBoundsException * If {@code begin} is negative, {@code begin} is greater than * {@code end}, or {@code end} is greater than {@code length}. */ ! static void checkBoundsBeginEnd(int begin, int end, int length) { if (begin < 0 || begin > end || end > length) { throw new StringIndexOutOfBoundsException( "begin " + begin + ", end " + end + ", length " + length); } }
< prev index next >