azure-sdk-for-java icon indicating copy to clipboard operation
azure-sdk-for-java copied to clipboard

Calling ServiceBusContract.deleteMessage() can throw NullPointerException

Open BillAtPros opened this issue 13 years ago • 3 comments

Dev estimate: 2 Test estimate: 1

Calling ServiceBusContract.deleteMessage() on a BrokeredMessage obtained with ReceiveMode.RECEIVE_AND_DELETE will cause a NPE to be thrown from java.net.URI while parsing. This is due to the fact that BrokeredMessage.getLockLocation() returns a null value for messages retrieved with ReceiveMode.RECEIVE_AND_DELETE. While it's obviously a bad idea to call deleteMessage() on messages retrieved in this fashion, an NPE is not an appropriate response. Instead, ServiceBusRestProxy.deleteMessage() should test BrokeredMessage.getLockLocation() for a valid value and throw a ServiceException if it is not valid.

All IMNSO, of course.

Happy to do the tests/implementation as soon as I can get the CLA through my company's legal.

Bill

BillAtPros avatar Mar 28 '13 22:03 BillAtPros

the same apply to unlock message.

gcheng avatar May 06 '13 20:05 gcheng

However, the proposed change is breaking change which we cannot take. For example, if customer already capture NPE, now they need to capture ServiceException. In addition, this is not a service exception, it doesn't make sense to throw a service exception for null pointer.

gcheng avatar May 06 '13 21:05 gcheng

I think customer should just check whether the lock duration is null before calling unlock message/delete message. Additional checking at service layer of SDK is not in scope, close for now.

gcheng avatar May 06 '13 21:05 gcheng