• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  * Copyright (c) 1994, 2019, 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     @java.io.Serial
40     private static final long serialVersionUID = -6762910422159637258L;
41 
42     /**
43      * Constructs a {@code StringIndexOutOfBoundsException} with no detail
44      * message.
45      */
StringIndexOutOfBoundsException()46     public StringIndexOutOfBoundsException() {
47         super();
48     }
49 
50     /**
51      * Constructs a {@code StringIndexOutOfBoundsException} with the specified
52      * detail message.
53      *
54      * @param s the detail message.
55      */
StringIndexOutOfBoundsException(String s)56     public StringIndexOutOfBoundsException(String s) {
57         super(s);
58     }
59 
60     /**
61      * Constructs a new {@code StringIndexOutOfBoundsException} class with an
62      * argument indicating the illegal index.
63      *
64      * <p>The index is included in this exception's detail message.  The
65      * exact presentation format of the detail message is unspecified.
66      *
67      * @param index the illegal index.
68      */
StringIndexOutOfBoundsException(int index)69     public StringIndexOutOfBoundsException(int index) {
70         super("String index out of range: " + index);
71     }
72 
73     // BEGIN Android-added: Additional constructors for internal use.
74     /**
75      * Used internally for consistent high-quality error reporting.
76      * @hide
77      */
StringIndexOutOfBoundsException(String s, int index)78     StringIndexOutOfBoundsException(String s, int index) {
79         this(s.length(), index);
80     }
81 
82     /**
83      * Used internally for consistent high-quality error reporting.
84      * @hide
85      */
StringIndexOutOfBoundsException(int sourceLength, int index)86     StringIndexOutOfBoundsException(int sourceLength, int index) {
87         super("length=" + sourceLength + "; index=" + index);
88     }
89 
90     /**
91      * Used internally for consistent high-quality error reporting.
92      * @hide
93      */
StringIndexOutOfBoundsException(String s, int offset, int count)94     StringIndexOutOfBoundsException(String s, int offset, int count) {
95         this(s.length(), offset, count);
96     }
97 
98     /**
99      * Used internally for consistent high-quality error reporting.
100      * @hide
101      */
StringIndexOutOfBoundsException(int sourceLength, int offset, int count)102     StringIndexOutOfBoundsException(int sourceLength, int offset,
103             int count) {
104         super("length=" + sourceLength + "; regionStart=" + offset
105                 + "; regionLength=" + count);
106     }
107     // END Android-added: Additional constructors for internal use.
108 }
109