metro-jax-ws icon indicating copy to clipboard operation
metro-jax-ws copied to clipboard

StringIndexOutOfBoundsException in MessageWriter.java Line 91

Open k-a-z-u opened this issue 5 months ago • 1 comments

Error

java.lang.StringIndexOutOfBoundsException: begin 0, end -9, length 43
in MessageWriter.write(String)

Reason

In Line 91 of com.sun.xml.ws.util.MessageWriter

super.write(str.substring(0, limit - size));

limit-size was negative, causing a StringIndexOutOfBoundsException

In my case, the involved values were: size = 4105 str.length() = 43 limit = 4096 limit - size = -9

Steps to Reproduce

Unfortunately, i could not trace the actual order and contents write(...) was called with. Aforementioned crash happened out of the blue today. However, i was able to craft something that can trigger the same behavior:

int limit = 4096;
com.sun.xml.ws.util.MessageWriter mw = new com.sun.xml.ws.util.MessageWriter(new StringWriter(), limit);
mw.write(new String(new char[limit - 40]));
mw.write("-- content-transfer-encoding: binary");
mw.write("");
mw.write("--");

should crash with

java.lang.StringIndexOutOfBoundsException: begin 0, end -14, length 2

Workaround

Quick-Fix for me was to reduce the logging level for com.sun.xml.*

k-a-z-u avatar Sep 19 '24 12:09 k-a-z-u