2012/10/12 <[email protected]>:
> Author: markt
> Date: Fri Oct 12 08:56:58 2012
> New Revision: 1397476
>
> URL: http://svn.apache.org/viewvc?rev=1397476&view=rev
> Log:
> Fix a long standing TODO so correct exceptions are thrown.
> Clean-up Javadoc.
>
> Modified:
> tomcat/tc7.0.x/trunk/ (props changed)
> tomcat/tc7.0.x/trunk/java/javax/servlet/http/HttpServlet.java
> tomcat/tc7.0.x/trunk/java/javax/servlet/http/HttpServletRequest.java
>
> Propchange: tomcat/tc7.0.x/trunk/
> ------------------------------------------------------------------------------
> Merged /tomcat/trunk:r1397464,1397466,1397472
>
> Modified: tomcat/tc7.0.x/trunk/java/javax/servlet/http/HttpServlet.java
> URL:
> http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/javax/servlet/http/HttpServlet.java?rev=1397476&r1=1397475&r2=1397476&view=diff
> ==============================================================================
> --- tomcat/tc7.0.x/trunk/java/javax/servlet/http/HttpServlet.java (original)
> +++ tomcat/tc7.0.x/trunk/java/javax/servlet/http/HttpServlet.java Fri Oct 12
> 08:56:58 2012
> @@ -837,14 +837,21 @@ class NoBodyOutputStream extends Servlet
>
> @Override
> public void write(byte buf[], int offset, int len) throws IOException {
> - if (len >= 0) {
> - contentLength += len;
> - } else {
> - // XXX
> - // isn't this really an IllegalArgumentException?
> + if (buf == null) {
> + throw new NullPointerException(
> + lStrings.getString("err.io.nullArray"));
> + }
>
> - String msg = lStrings.getString("err.io.negativelength");
> - throw new IOException(msg);
> + if (offset < 0 || len < 0 || offset+len < buf.length) {
Two errors:
1. The above condition should be "offset+len > buf.length"
This went undetected by the test suite: none of the tests on the
buildbot are failing (besides the TestSsl x NIO one). Well, usually
offset==0 and len==buf.length, so it is no wonder.
> + String msg = lStrings.getString("err.io.indexOutOfBounds");
> + Object[] msgArgs = new Object[3];
> + msgArgs[0] = Integer.valueOf(offset);
> + msgArgs[1] = Integer.valueOf(len);
> + msgArgs[2] = Integer.valueOf(offset + len);
2. The above value for [2] should be Integer.valueOf(buf.length), as
the message pattern says:
err.io.indexOutOfBounds=Invalid offset [{0}] and / or length [{1}]
specified for array of size [{2}]
> + msg = MessageFormat.format(msg, msgArgs);
> + throw new IndexOutOfBoundsException(msg);
> }
> +
> + contentLength += len;
> }
> }
>
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]