1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. Oracle designates this 9 * particular file as subject to the "Classpath" exception as provided 10 * by Oracle in the LICENSE file that accompanied this code. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23 * or visit www.oracle.com if you need additional information or have any 24 * questions. 25 */ 26 27 package java.lang; 28 29 /** 30 * Thrown by {@code String} methods to indicate that an index is either negative 31 * or greater than the size of the string. For some methods such as the 32 * {@link String#charAt charAt} method, this exception also is thrown when the 33 * index is equal to the size of the string. 34 * 35 * @see java.lang.String#charAt(int) 36 * @since 1.0 37 */ 38 public class StringIndexOutOfBoundsException extends IndexOutOfBoundsException { 39 private static final long serialVersionUID = -6762910422159637258L; 40 41 /** 42 * Constructs a {@code StringIndexOutOfBoundsException} with no detail 43 * message. 44 */ StringIndexOutOfBoundsException()45 public StringIndexOutOfBoundsException() { 46 super(); 47 } 48 49 /** 50 * Constructs a {@code StringIndexOutOfBoundsException} with the specified 51 * detail message. 52 * 53 * @param s the detail message. 54 */ StringIndexOutOfBoundsException(String s)55 public StringIndexOutOfBoundsException(String s) { 56 super(s); 57 } 58 59 /** 60 * Constructs a new {@code StringIndexOutOfBoundsException} class with an 61 * argument indicating the illegal index. 62 * 63 * <p>The index is included in this exception's detail message. The 64 * exact presentation format of the detail message is unspecified. 65 * 66 * @param index the illegal index. 67 */ StringIndexOutOfBoundsException(int index)68 public StringIndexOutOfBoundsException(int index) { 69 super("String index out of range: " + index); 70 } 71 72 // BEGIN Android-added: Additional constructors for internal use. 73 /** 74 * Used internally for consistent high-quality error reporting. 75 * @hide 76 */ StringIndexOutOfBoundsException(String s, int index)77 StringIndexOutOfBoundsException(String s, int index) { 78 this(s.length(), index); 79 } 80 81 /** 82 * Used internally for consistent high-quality error reporting. 83 * @hide 84 */ StringIndexOutOfBoundsException(int sourceLength, int index)85 StringIndexOutOfBoundsException(int sourceLength, int index) { 86 super("length=" + sourceLength + "; index=" + index); 87 } 88 89 /** 90 * Used internally for consistent high-quality error reporting. 91 * @hide 92 */ StringIndexOutOfBoundsException(String s, int offset, int count)93 StringIndexOutOfBoundsException(String s, int offset, int count) { 94 this(s.length(), offset, count); 95 } 96 97 /** 98 * Used internally for consistent high-quality error reporting. 99 * @hide 100 */ StringIndexOutOfBoundsException(int sourceLength, int offset, int count)101 StringIndexOutOfBoundsException(int sourceLength, int offset, 102 int count) { 103 super("length=" + sourceLength + "; regionStart=" + offset 104 + "; regionLength=" + count); 105 } 106 // END Android-added: Additional constructors for internal use. 107 } 108