Skip to content

Commit

Permalink
Issue eclipse-ee4j#2016 Fixed NPE on missing CloseReason
Browse files Browse the repository at this point in the history
- original code was throwing NPE
- handler can be null
  - then we have nothing to handle the reason
- closeReason can be null
  - then we use "locally closed" as a default (may be incorrect)
- even ignored exception should be visible somewhere (logging)

Signed-off-by: David Matějček <dmatej@seznam.cz>
  • Loading branch information
dmatej committed Nov 20, 2020
1 parent 8986bb8 commit 2c531b4
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.logging.Logger;

import org.glassfish.grizzly.Buffer;
import org.glassfish.grizzly.CloseReason;
import org.glassfish.grizzly.CompletionHandler;
import org.glassfish.grizzly.Connection;
import org.glassfish.grizzly.FileTransfer;
Expand Down Expand Up @@ -791,8 +792,14 @@ public void notifyCanWrite(final WriteHandler handler) {
throw new IllegalStateException("Illegal attempt to set a new handler before the existing handler has been notified.");
}

if (!httpContext.getCloseable().isOpen()) {
handler.onError(connection.getCloseReason().getCause());
if (handler != null && !httpContext.getCloseable().isOpen()) {
final CloseReason closeReason = connection.getCloseReason();
if (closeReason == null) {
LOGGER.log(Level.WARNING, "No close reason set, using default: {0}", CloseReason.LOCALLY_CLOSED_REASON);
handler.onError(CloseReason.LOCALLY_CLOSED_REASON.getCause());
} else {
handler.onError(closeReason.getCause());
}
return;
}

Expand Down Expand Up @@ -820,6 +827,7 @@ public void notifyCanWrite(final WriteHandler handler) {
// have been processed by WriteHandler.onError().
httpContext.getOutputSink().notifyCanWrite(asyncWriteHandler);
} catch (Exception ignored) {
LOGGER.log(Level.FINE, "Ignoring exception.", ignored);
}
}

Expand Down

0 comments on commit 2c531b4

Please sign in to comment.