-
Bug
-
Resolution: Fixed
-
P2
-
7
java.lang.StringBuilder.ensureCapacity(int minCap) method throws OutOfMemoryError Exception with the minCap value near to the Integer.MIN_VALUE.
See the following simple code:
public class TestEnsureCapacity {
public static void main(String[] args) {
StringBuilder sb = new StringBuffer("abc");
int cap = sb.capacity();
sb.ensureCapacity(Integer.MIN_VALUE);
}
}
The Exception message will be thrown:
Exception in thread "main" java.lang.OutOfMemoryError
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:125)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:112)
at java.lang.AbstractStringBuilder.ensureCapacity(AbstractStringBuilder.java:103)
at java.lang.StringBuilder.ensureCapacity(StringBuilder.java:72)
at TestEnsureCapacity.main(TestEnsureCapacity.java:6)
In that time JDK specification say nothing about possible exceptions for the java.lang.StringBuilder.ensureCapacity method: If the minimumCapacity argument is nonpositive, this method takes no action and simply returns.
This is regression since JDK 7 b94.
See the following simple code:
public class TestEnsureCapacity {
public static void main(String[] args) {
StringBuilder sb = new StringBuffer("abc");
int cap = sb.capacity();
sb.ensureCapacity(Integer.MIN_VALUE);
}
}
The Exception message will be thrown:
Exception in thread "main" java.lang.OutOfMemoryError
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:125)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:112)
at java.lang.AbstractStringBuilder.ensureCapacity(AbstractStringBuilder.java:103)
at java.lang.StringBuilder.ensureCapacity(StringBuilder.java:72)
at TestEnsureCapacity.main(TestEnsureCapacity.java:6)
In that time JDK specification say nothing about possible exceptions for the java.lang.StringBuilder.ensureCapacity method: If the minimumCapacity argument is nonpositive, this method takes no action and simply returns.
This is regression since JDK 7 b94.
- duplicates
-
JDK-7000529 java/lang/StringBuilder/EnsureCapacity.java fails with all build of JDK 7
-
- Closed
-
- relates to
-
JDK-6955504 (str) String[Builder/Buffer].append(char[],int,int) throws OutOfMemoryError in b94
-
- Closed
-
-
JDK-6933217 Huge arrays handled poorly in core libraries
-
- Closed
-