okleine / nCoAP

Java implementation of the CoAP protocol using netty
BSD 3-Clause "New" or "Revised" License
179 stars 57 forks source link

NullPointerException in CoapMessageEncoder.encodeHeader() #13

Closed stefanhueske closed 11 years ago

stefanhueske commented 12 years ago

Creating a CoapRespose via constructor CoapResponse(Code code) leads to a msgType value of null. Trying to encode this CoapRespose causes a NullPointerException in CoapMessageEncoder.encodeHeader().

okleine commented 11 years ago

This is ok and rather a feature. Since there is no message type set, there is no encoding possible. This will not happen in a real server application since the framework automatically sets a proper message type.

E.g., a webservice that wants to send a response on a confirmable request cannot know if there was already an empty acknowledgement sent. So, it cannot decide wether to set CON or ACK as message type. Thus, this implementation leaves it to the framework to set the message type properly.

If there is any need to set a message type manually, one can use response.getHeader().setMsgType(type). Using this in combination with the framework, i.e. the handlers, may (and propably will) cause unexpected behaviour.