Canceling an asynchronous IO operation throws NPE

Umashankar Umashankar.Ningaiah at Sun.COM
Mon Jul 28 08:19:08 PDT 2008

Alan Bateman wrote:
> Umashankar wrote:
>> Hi Alan,
>> On canceling an IO operation that is in progress,I get a 
>> CancellationException which is expected as per the spec.
>> But in the stack trace, I also see a NullPointerException.
>> Following is the stack trace.
>>    java.util.concurrent.CancellationException
>>        at
>>        at 
>> AsyncIOCancelTests.testWrite2FileChannel_01(
>>        at AsyncIOCancelTests.main(
>> Exception in thread "Thread-1" java.lang.NullPointerException
>>        at$
>>        at 
>> java.util.concurrent.ThreadPoolExecutor.runWorker( 
>>        at 
>> java.util.concurrent.ThreadPoolExecutor$ 
>>        at
>> Please let me know if this is correct.
> There's a bug here - thanks! It arises when you cancel an I/O 
> operation that doesn't have a CompletionHandler but the code is trying 
> to invoke its cancelled method. It should be harmless (meaning an 
> annoyance printed to the console) and I'll fix it for the next build.
> -Alan.

In my case I am specifying a CompletionHandler to the write() operation 
that I cancel immediately after initiating it.


More information about the nio-dev mailing list