I'm getting the following very strange error from my server application (running Java 7):
Caused by: java.lang.OutOfMemoryError: Requested array size exceeds VM limit
at java.util.Arrays.copyOf(Arrays.java:2367)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:130)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:415)
at java.lang.StringBuffer.append(StringBuffer.java:237)
at java.io.StringWriter.write(StringWriter.java:101)
at java.io.PrintWriter.newLine(PrintWriter.java:480)
at java.io.PrintWriter.println(PrintWriter.java:629)
at java.io.PrintWriter.println(PrintWriter.java:757)
at java.lang.Throwable$WrappedPrintWriter.println(Throwable.java:764)
at java.lang.Throwable.printStackTrace(Throwable.java:655)
at java.lang.Throwable.printStackTrace(Throwable.java:721)
Looking at PrintWriter.java:480:
out.write(lineSeparator);
lineSeperator
is set in the constructor of PrintWriter, as follows:
lineSeparator = java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.seperator"));
I've rerun my application twice on this particular data set, and I get the same exception at the exact same place twice. It seems very unlikely to me that it would be the append of the new line seperator (which should be just "\n") that would cause the OOM.
The printStackTrace
function in the trace above is called from:
public static String getMessage(Throwable t) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw); // THIS LINE <-----
return sw.toString();
}
Has anyone seen anything similar, or know if the lineSeperator
could somehow get really long?