Code Review 6980517: TEST_BUG sun\net\www\http\ChunkedInputStream\ChunkedEncodingTest.java NullPointerException

Chris Hegarty chris.hegarty at oracle.com
Fri Sep 10 03:29:06 PDT 2010


Michael,

The test compares the hash of the data sent by the server to the hash of 
the data received by the client. This validates the chunked input stream 
implementation. The hash of the data sent by the server is computed and 
stored in serverMac (byte[]). serverMac is not set until after all the 
data is sent, at which point the client thread can proceed to do the 
comparison, but serverMac may not have been set yet. 
MessageDigest.isEqual blows up with NullPointerException.

In fact, this test (ChunkedEncodingTest) does not even used chunked 
encoding. The server invokes sendResponseHeaders with the 
MESSAGE_LENGTH. This causes the content-length header to be set in the 
response and for an output stream to be created to transfer the response 
body. The test should invoke sendResponseHeader with 0 to use chunked 
encoding. This also fixes the race condition since the serverMac is set 
before the output stream is closed, and since we're using chunked 
encoding the final is not written until the output stream is closed.

Webrev:
   http://cr.openjdk.java.net/~chegar/6980517/webrev.00/webrev/

-Chris.



More information about the net-dev mailing list