dev@grizzly.java.net

a potential NullPointerException in comet CometContext.java

From: Shing Wai Chan <Shing-Wai.Chan_at_Sun.COM>
Date: Wed, 12 Dec 2007 10:06:25 -0800

Hi,

While investing on comet, I see a potential NullPointerException in
CometContext.java.
I have enclosed my proposed fix below.

Regards,
     Shing Wai Chan

Encl:
/export/grizzly/src/grizzly/trunk/modules/comet/src/main/java/com/sun/grizzly/comet
> svn diff CometContext.java
Index: CometContext.java
===================================================================
--- CometContext.java (revision 663)
+++ CometContext.java (working copy)
@@ -583,8 +583,11 @@
     * @oaram handler The CometHandler that will be invoked.
     */
    public boolean registerAsyncRead(CometHandler handler){
- SelectionKey key = handlers.get(handler);
- if (handler == null){
+ SelectionKey key = null;
+ if (handler != null) {
+ key = handlers.get(handler);
+ }
+ if (handler == null || key == null) {
            throw new
               IllegalStateException(INVALID_COMET_HANDLER);
        }
@@ -606,8 +609,11 @@
     * Register for asynchronous write.
     */
    public boolean registerAsyncWrite(CometHandler handler){
- SelectionKey key = handlers.get(handler);
- if (handler == null || key == null){
+ SelectionKey key = null;
+ if (handler != null) {
+ key = handlers.get(handler);
+ }
+ if (handler == null || key == null) {
            throw new
               IllegalStateException(INVALID_COMET_HANDLER);
        }