javax.xml.soap.SOAPMessage.getSOAPHeader() is recorded in jdkBaseNonnullReturn.db as never returning null, but it can and will do so when a header has been deleted from the SOAP body, as per the JDK documentation. This results in incorrect assertions by findbugs that a null check is unnecessary. Bug present in 3.0.1 release.
Could you please provide exact link to the documentation where it says that null can be returned?
I'm reading here:
public SOAPHeader getSOAPHeader()
throws SOAPException
Gets the SOAP Header contained in this SOAPMessage object.
Returns:
the SOAPHeader object contained by this SOAPMessage object
Throws:
SOAPException - if the SOAP Header does not exist or cannot be retrieved
It says that exception will be thrown if SOAP header does not exist.
Hi,
Ah, sorry, it's a bit obtuse, since SOAPMessage.getSOAPHeader() is a shortcut for SOAPMessage.getSOAPPart().getEnvelope().getHeader():
https://docs.oracle.com/javaee/7/api/javax/xml/soap/SOAPEnvelope.html#getHeader()
Returns:
the SOAPHeader object or null if there is none
edit: Demonstrator project here: https://github.com/codebje/findbugs-soap-null-example
Last edit: bje 2015-03-16
thanks.