diff options
Diffstat (limited to 'java/lang/String.java')
-rw-r--r-- | java/lang/String.java | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/java/lang/String.java b/java/lang/String.java index fdec7f929..c3c92a178 100644 --- a/java/lang/String.java +++ b/java/lang/String.java @@ -277,7 +277,8 @@ public final class String throw new StringIndexOutOfBoundsException("offset: " + offset); if (count < 0) throw new StringIndexOutOfBoundsException("count: " + count); - if (offset + count < 0 || offset + count > ascii.length) + // equivalent to: offset + count < 0 || offset + count > ascii.length + if (ascii.length - offset < count) throw new StringIndexOutOfBoundsException("offset + count: " + (offset + count)); value = new char[count]; @@ -342,7 +343,8 @@ public final class String throw new StringIndexOutOfBoundsException("offset: " + offset); if (count < 0) throw new StringIndexOutOfBoundsException("count: " + count); - if (offset + count < 0 || offset + count > data.length) + // equivalent to: offset + count < 0 || offset + count > data.length + if (data.length - offset < count) throw new StringIndexOutOfBoundsException("offset + count: " + (offset + count)); try @@ -422,7 +424,8 @@ public final class String throw new StringIndexOutOfBoundsException("offset: " + offset); if (count < 0) throw new StringIndexOutOfBoundsException("count: " + count); - if (offset + count < 0 || offset + count > data.length) + // equivalent to: offset + count < 0 || offset + count > data.length + if (data.length - offset < count) throw new StringIndexOutOfBoundsException("offset + count: " + (offset + count)); int o, c; @@ -537,7 +540,8 @@ public final class String throw new StringIndexOutOfBoundsException("offset: " + offset); if (count < 0) throw new StringIndexOutOfBoundsException("count: " + count); - if (offset + count < 0 || offset + count > data.length) + // equivalent to: offset + count < 0 || offset + count > data.length + if (data.length - offset < count) throw new StringIndexOutOfBoundsException("offset + count: " + (offset + count)); if (dont_copy) @@ -1763,7 +1767,7 @@ public final class String /** * Return the number of code points between two indices in the - * <code>StringBuffer</code>. An unpaired surrogate counts as a + * <code>String</code>. An unpaired surrogate counts as a * code point for this purpose. Characters outside the indicated * range are not examined, even if the range ends in the middle of a * surrogate pair. @@ -1881,6 +1885,8 @@ public final class String * described in s. * @param s the CharSequence * @return true iff this String contains s + * + * @since 1.5 */ public boolean contains (CharSequence s) { |