dev@grizzly.java.net

Trivial NPE in SuspendableFilter#resume()

From: Bongjae Chang <carryel_at_korea.com>
Date: Wed, 1 Jul 2009 23:51:05 +0900

When I ran SuspendableTest, I saw NPE.

Here is log.
---
Running com.sun.grizzly.SuspendableTest
2009. 7. 1 ¿ÀÈÄ 11:18:38 com.sun.grizzly.Controller start
Á¤º¸: Starting Grizzly Framework 1.9.17-SNAPSHOT - Wed Jul 01 23:18:38 KST 2009
2009. 7. 1 ¿ÀÈÄ 11:18:38 com.sun.grizzly.Controller start
Á¤º¸: Starting Grizzly Framework 1.9.17-SNAPSHOT - Wed Jul 01 23:18:38 KST 2009
Response: This is a suspendable request
expired
resumed
Resumed after:5000
2009. 7. 1 ¿ÀÈÄ 11:18:45 com.sun.grizzly.Controller start
Á¤º¸: Starting Grizzly Framework 1.9.17-SNAPSHOT - Wed Jul 01 23:18:45 KST 2009
2009. 7. 1 ¿ÀÈÄ 11:18:45 com.sun.grizzly.Controller start
Á¤º¸: Starting Grizzly Framework 1.9.17-SNAPSHOT - Wed Jul 01 23:18:45 KST 2009
expired
resumed
Now trying to push bytes on a suspended request. Must wait for 5 seconds.
expired
resumed
Resumed after:5000
2009. 7. 1 ¿ÀÈÄ 11:18:57 com.sun.grizzly.Controller start
Á¤º¸: Starting Grizzly Framework 1.9.17-SNAPSHOT - Wed Jul 01 23:18:57 KST 2009
2009. 7. 1 ¿ÀÈÄ 11:18:57 com.sun.grizzly.Controller start
Á¤º¸: Starting Grizzly Framework 1.9.17-SNAPSHOT - Wed Jul 01 23:18:57 KST 2009
interrupted
2009. 7. 1 ¿ÀÈÄ 11:19:04 com.sun.grizzly.Controller start
Á¤º¸: Starting Grizzly Framework 1.9.17-SNAPSHOT - Wed Jul 01 23:19:04 KST 2009
2009. 7. 1 ¿ÀÈÄ 11:19:04 com.sun.grizzly.Controller start
Á¤º¸: Starting Grizzly Framework 1.9.17-SNAPSHOT - Wed Jul 01 23:19:04 KST 2009
Response: This is a suspendable request
Now trying cancelling
interrupted
2009. 7. 1 ¿ÀÈÄ 11:19:08 com.sun.grizzly.Controller start
Á¤º¸: Starting Grizzly Framework 1.9.17-SNAPSHOT - Wed Jul 01 23:19:08 KST 2009
2009. 7. 1 ¿ÀÈÄ 11:19:08 com.sun.grizzly.Controller start
Á¤º¸: Starting Grizzly Framework 1.9.17-SNAPSHOT - Wed Jul 01 23:19:08 KST 2009
Response: This is a suspendable request
Now trying cancelling
expired
2009. 7. 1 ¿ÀÈÄ 11:19:09 com.sun.grizzly.suspendable.SuspendableMonitor run
½É°¢: SuspendableMonitor
java.lang.NullPointerException
        at com.sun.grizzly.suspendable.SuspendableFilter.resume(SuspendableFilter.java:436)
        at com.sun.grizzly.suspendable.SuspendableMonitor.expireIdleKeys(SuspendableMonitor.java:186
)
        at com.sun.grizzly.suspendable.SuspendableMonitor.run(SuspendableMonitor.java:121)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
        at java.lang.Thread.run(Thread.java:619)
resumed
Now trying to push bytes on a resumed request
Took:2000
Response2: This is a suspendable request
2009. 7. 1 ¿ÀÈÄ 11:19:12 com.sun.grizzly.Controller start
Á¤º¸: Starting Grizzly Framework 1.9.17-SNAPSHOT - Wed Jul 01 23:19:12 KST 2009
2009. 7. 1 ¿ÀÈÄ 11:19:12 com.sun.grizzly.Controller start
Á¤º¸: Starting Grizzly Framework 1.9.17-SNAPSHOT - Wed Jul 01 23:19:12 KST 2009
Send and get resumed using Suspendable
Now trying resuming
resumed
Now reading bytes
Took:5000
Response2: This is a suspendable request
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 41.063 sec
---

The proposed patch is the following.

Index: com/sun/grizzly/suspendable/SuspendableFilter.java
===================================================================
--- com/sun/grizzly/suspendable/SuspendableFilter.java (revision 3404)
+++ com/sun/grizzly/suspendable/SuspendableFilter.java (working copy)
@@ -433,7 +433,7 @@
      */
     protected boolean resume(SelectionKey key){
         KeyHandler kh = suspendedKeys.remove(key);
- if (kh.getSuspendableHandler() == null){
+ if (kh == null || kh.getSuspendableHandler() == null){
             return false;
         }
         if (logger.isLoggable(Level.FINE)) {

Thanks.

--
Bongjae Chang