This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new f562edd  Avoid other cases of NPEs on stop
f562edd is described below

commit f562edd3302866f34c0ca9fa97f6ff414450f1ae
Author: remm <r...@apache.org>
AuthorDate: Mon May 13 09:43:29 2019 +0200

    Avoid other cases of NPEs on stop
    
    As found in the CI logs.
---
 java/org/apache/catalina/core/StandardWrapperValve.java |  2 ++
 java/org/apache/coyote/http11/Http11InputBuffer.java    |  9 ++++++++-
 java/org/apache/coyote/http11/Http11OutputBuffer.java   | 10 +++++++++-
 webapps/docs/changelog.xml                              |  3 +--
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/catalina/core/StandardWrapperValve.java 
b/java/org/apache/catalina/core/StandardWrapperValve.java
index ae7b319..aff0b42 100644
--- a/java/org/apache/catalina/core/StandardWrapperValve.java
+++ b/java/org/apache/catalina/core/StandardWrapperValve.java
@@ -29,6 +29,7 @@ import javax.servlet.ServletException;
 import javax.servlet.UnavailableException;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.catalina.Container;
 import org.apache.catalina.Context;
 import org.apache.catalina.Globals;
 import org.apache.catalina.LifecycleException;
@@ -174,6 +175,7 @@ final class StandardWrapperValve
 
         // Call the filter chain for this request
         // NOTE: This also calls the servlet's service() method
+        Container container = this.container;
         try {
             if ((servlet != null) && (filterChain != null)) {
                 // Swallow output if needed
diff --git a/java/org/apache/coyote/http11/Http11InputBuffer.java 
b/java/org/apache/coyote/http11/Http11InputBuffer.java
index 15a7e83..5632de2 100644
--- a/java/org/apache/coyote/http11/Http11InputBuffer.java
+++ b/java/org/apache/coyote/http11/Http11InputBuffer.java
@@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 
+import org.apache.coyote.CloseNowException;
 import org.apache.coyote.InputBuffer;
 import org.apache.coyote.Request;
 import org.apache.juli.logging.Log;
@@ -728,7 +729,13 @@ public class Http11InputBuffer implements InputBuffer, 
ApplicationBufferHandler
             byteBuffer.position(byteBuffer.limit());
         }
         byteBuffer.limit(byteBuffer.capacity());
-        int nRead = wrapper.read(block, byteBuffer);
+        SocketWrapperBase<?> socketWrapper = this.wrapper;
+        int nRead = -1;
+        if (socketWrapper != null) {
+            nRead = socketWrapper.read(block, byteBuffer);
+        } else {
+            throw new CloseNowException(sm.getString("iib.eof.error"));
+        }
         byteBuffer.limit(byteBuffer.position()).reset();
         if (nRead > 0) {
             return true;
diff --git a/java/org/apache/coyote/http11/Http11OutputBuffer.java 
b/java/org/apache/coyote/http11/Http11OutputBuffer.java
index 62d5223..c369837 100644
--- a/java/org/apache/coyote/http11/Http11OutputBuffer.java
+++ b/java/org/apache/coyote/http11/Http11OutputBuffer.java
@@ -21,6 +21,7 @@ import java.nio.ByteBuffer;
 import java.util.Arrays;
 
 import org.apache.coyote.ActionCode;
+import org.apache.coyote.CloseNowException;
 import org.apache.coyote.Response;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
@@ -306,6 +307,8 @@ public class Http11OutputBuffer implements HttpOutputBuffer 
{
                 SocketWrapperBase<?> socketWrapper = this.socketWrapper;
                 if (socketWrapper != null) {
                     socketWrapper.write(isBlocking(), headerBuffer);
+                } else {
+                    throw new 
CloseNowException(sm.getString("iob.failedwrite"));
                 }
             } finally {
                 headerBuffer.position(0).limit(headerBuffer.capacity());
@@ -530,7 +533,12 @@ public class Http11OutputBuffer implements 
HttpOutputBuffer {
         public int doWrite(ByteBuffer chunk) throws IOException {
             try {
                 int len = chunk.remaining();
-                socketWrapper.write(isBlocking(), chunk);
+                SocketWrapperBase<?> socketWrapper = 
Http11OutputBuffer.this.socketWrapper;
+                if (socketWrapper != null) {
+                    socketWrapper.write(isBlocking(), chunk);
+                } else {
+                    throw new 
CloseNowException(sm.getString("iob.failedwrite"));
+                }
                 len -= chunk.remaining();
                 byteCount += len;
                 return len;
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 72a7da2..1946863 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -81,8 +81,7 @@
         certain microbenchmarks. (remm)
       </fix>
       <fix>
-        Avoid possible NPE in <code>Http11OutputBuffer.commit</code> on
-        connector stopclose. (remm)
+        Avoid possible NPEs in on connector stop. (remm)
       </fix>
     </changelog>
   </subsection>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to