DescriptionEOFException.getMessage returns null because of an inconsistency between readTrailer() and readUByte() when handling eof.
This change is meant to ignore this exception as the contents of the http response have actually been read and processed.
Details:
Please take a look at the stack trace of exception which is actually thrown before reading the analysis below:
What seems to be happening is:
toByteArray calls instream.read continously and stops when -1 is returned by instream.read
instream = EofSensorInputStream with wrappedstream as GZIPInputStream.read() method calls wrappedStream.read(byte)
FilteredInputStream.read(byte[]) calls this.read(byte[], 0, length)
GZIPInputStream.read(byte[], offset, len) returns -1 if end of stream is reached, otherwise it calls super.read(). This call returns -1
Now it calls readTrailer() and then is supposed to set end of stream reached = true
readTrailer() calls readUInt(in) [ in = input stream being read, which in this case is org.apache.http.impl.io.ContentLengthInputStream ]
readUInt() calls readUShort
readUShort() calls readUByte
readUByte() calls in.read() which returns -1. readUByte checks if its -1 and throws EOFException with no message :( :(
This exception is caught by EofSensorInputStream.read() and it passes the exception along as is, without enclosing it in some other exception.
This is now caught by BasicHttpFetcher.toByteArraySafe() which checks if eofe.getMessage().equals("Unexpected end of ZLIB input stream") and this throws the NullPointerException because the message was never set by any1
What seems to be an obvious bug here is that readUByte does not want input stream to return -1, whereas readTrailer() is specifically called when the stream returns -1.
A bug has been filed with Sun and will update the code with the bug id once Sun has accepted the bug.
java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:224)
java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:214)
java.util.zip.GZIPInputStream.readUInt(GZIPInputStream.java:206)
java.util.zip.GZIPInputStream.readTrailer(GZIPInputStream.java:196)
java.util.zip.GZIPInputStream.read(GZIPInputStream.java:111)
java.io.FilterInputStream.read(FilterInputStream.java:107)
org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:178)
org.apache.shindig.gadgets.http.BasicHttpFetcher.toByteArraySafe(BasicHttpFetcher.java:513)
org.apache.shindig.gadgets.http.BasicHttpFetcher.makeResponse(BasicHttpFetcher.java:469)
org.apache.shindig.gadgets.http.BasicHttpFetcher.fetch(BasicHttpFetcher.java:365)
com.google.gadgets.server.fetcher.RoutedHttpFetcher$RoutedHttpFetcherWrapper.fetch(RoutedHttpFetcher.java:34)
com.google.gadgets.server.tracker.ResourceUsageListener$TrackedFetcher.fetch(ResourceUsageListener.java:355)
com.google.gadgets.server.fetcher.RoutingHttpFetcher.fetch(RoutingHttpFetcher.java:54)
com.google.gadgets.server.fetcher.FilteredHttpFetcher.fetch(FilteredHttpFetcher.java:66)
com.google.gadgets.server.GoogleRequestPipeline.fetchNoCache(GoogleRequestPipeline.java:296)
com.google.gadgets.server.GoogleRequestPipeline.fetchWithCache(GoogleRequestPipeline.java:249)
com.google.gadgets.server.GoogleRequestPipeline.batchFetch(GoogleRequestPipeline.java:203)
com.google.gadgets.server.GoogleRequestPipeline.execute(GoogleRequestPipeline.java:142)
org.apache.shindig.gadgets.servlet.AccelHandler.doFetch(AccelHandler.java:84)
org.apache.shindig.gadgets.servlet.ProxyBase.fetch(ProxyBase.java:165)
org.apache.shindig.gadgets.servlet.HtmlAccelServlet.doGet(HtmlAccelServlet.java:63)
Patch Set 1 #Patch Set 2 : adding_else_clause #
Total comments: 4
Patch Set 3 : addressing_vikas_comments #Patch Set 4 : small_indent_fix #Patch Set 5 : fixing_loopholes_in_tests #
Total comments: 2
Patch Set 6 : addressing_vikas_comments #Patch Set 7 : syncing_to_head #
MessagesTotal messages: 12
|
||||||||||||||||||||||||||||