@@ -44,6 +44,7 @@ public UTF16String(long pointer) {
4444 */
4545 public byte byteAt (int index ) {
4646 checkIndex (index , byteLength ());
47+ checkAccess ();
4748 return Native .byteAt (getNativeObject (), index );
4849 }
4950
@@ -54,6 +55,7 @@ public byte byteAt(int index) {
5455 */
5556 public void setByteAt (int index , byte b ) {
5657 checkIndex (index , byteLength ());
58+ checkAccess ();
5759 Native .setByteAt (getNativeObject (), index , b );
5860 }
5961
@@ -66,6 +68,7 @@ public void setByteAt(int index, byte b) {
6668 @ Override
6769 public char charAt (int index ) {
6870 checkIndex (index , length ());
71+ checkAccess ();
6972 return Native .chatAt (getNativeObject (), index );
7073 }
7174
@@ -76,6 +79,7 @@ public char charAt(int index) {
7679 */
7780 public void setCharAt (int index , char c ) {
7881 checkIndex (index , length ());
82+ checkAccess ();
7983 Native .setCharAt (getNativeObject (), index , c );
8084 }
8185
@@ -85,6 +89,7 @@ public void setCharAt(int index, char c) {
8589 * @param string The string to append.
8690 */
8791 public void append (String string ) {
92+ checkAccess ();
8893 Native .append (getNativeObject (), string );
8994 }
9095
@@ -98,6 +103,7 @@ public void append(String string) {
98103 */
99104 public void append (String string , int fromIndex , int length ) {
100105 checkStringRange (string , fromIndex , length );
106+ checkAccess ();
101107 Native .appendPart (getNativeObject (), string , fromIndex , length );
102108 }
103109
@@ -113,7 +119,9 @@ public void insert(int index, String string) {
113119 append (string );
114120 return ;
115121 }
122+
116123 checkIndex (index , length ());
124+ checkAccess ();
117125 Native .insert (getNativeObject (), string , index );
118126 }
119127
@@ -128,6 +136,8 @@ public void delete(int fromIndex, int toIndex) {
128136 int size = length ();
129137 checkIndex (fromIndex , size );
130138 checkIndex (toIndex , size + 1 );
139+
140+ checkAccess ();
131141 Native .deleteChars (getNativeObject (), fromIndex , toIndex );
132142 }
133143
@@ -141,6 +151,8 @@ public void deleteBytes(int fromIndex, int toIndex) {
141151 int size = byteLength ();
142152 checkIndex (fromIndex , size );
143153 checkIndex (toIndex , size + 1 );
154+
155+ checkAccess ();
144156 Native .deleteBytes (getNativeObject (), fromIndex , toIndex );
145157 }
146158
@@ -161,6 +173,8 @@ public void replaceChars(int fromIndex, int toIndex, String str) {
161173 int size = length ();
162174 checkIndex (fromIndex , size );
163175 checkIndex (toIndex , size + 1 );
176+
177+ checkAccess ();
164178 Native .replaceChars (getNativeObject (), fromIndex , toIndex , str );
165179 }
166180
@@ -181,6 +195,8 @@ public void replaceBytes(int fromIndex, int toIndex, String str) {
181195 int size = byteLength ();
182196 checkIndex (fromIndex , size );
183197 checkIndex (toIndex , size + 1 );
198+
199+ checkAccess ();
184200 Native .replaceBytes (getNativeObject (), fromIndex , toIndex , str );
185201 }
186202
@@ -206,6 +222,8 @@ public UTF16String subseqChars(int start, int end) {
206222 int size = length ();
207223 checkIndex (start , size );
208224 checkIndex (end , size + 1 );
225+
226+ checkAccess ();
209227 return UTF16StringFactory .createString (Native .substring_chars (getNativeObject (), start , end ));
210228 }
211229
@@ -232,6 +250,8 @@ public UTF16String subseqBytes(int start, int end) {
232250 int size = byteLength ();
233251 checkIndex (start , size );
234252 checkIndex (end , size + 1 );
253+
254+ checkAccess ();
235255 return UTF16StringFactory .createString (Native .substring_bytes (getNativeObject (), start , end ));
236256 }
237257
@@ -258,6 +278,8 @@ public String substringChars(int start, int end) {
258278 int size = length ();
259279 checkIndex (start , size );
260280 checkIndex (end , size + 1 );
281+
282+ checkAccess ();
261283 return Native .subjstring_chars (getNativeObject (), start , end );
262284 }
263285
@@ -284,6 +306,8 @@ public String substringBytes(int start, int end) {
284306 int size = byteLength ();
285307 checkIndex (start , size );
286308 checkIndex (end , size + 1 );
309+
310+ checkAccess ();
287311 return Native .subjstring_bytes (getNativeObject (), start , end );
288312 }
289313
@@ -293,6 +317,7 @@ public String substringBytes(int start, int end) {
293317 * @return The length in characters.
294318 */
295319 public int length () {
320+ checkAccess ();
296321 return Native .length (getNativeObject ());
297322 }
298323
@@ -302,6 +327,7 @@ public int length() {
302327 * @return The length in bytes.
303328 */
304329 public int byteLength () {
330+ checkAccess ();
305331 return Native .byteLength (getNativeObject ());
306332 }
307333
@@ -323,6 +349,7 @@ public void closeNativeObj() {
323349
324350 @ Override
325351 public String toString () {
352+ checkAccess ();
326353 return Native .toString (getNativeObject ());
327354 }
328355
0 commit comments