Search |
||
Compiling your own byte array Trojan with JAXB 2.0Posted by felipegaucho on September 17, 2008 at 7:16 AM PDT
When I started using continuous integration against my own code, the very first results were buggy as expected, a lot of warnings, bugs and minor mistakes. Step by step, I am tailoring my source code in order to satisfy the quality criteria of PMD and Findbugs, but some warnings persist and some of them make me worry about the code quality I am delivering to my customers. From the controversial analysis results, one specific issue remains unanswered: the exposition of internal representation of mutable objects. The risks of exposing internal representation of mutable objectsProblem description: imagine you have a class member of type array of bytes, and imagine the public getter method of this field returns a reference to the array. It allows any external code to manipulate the contents of this field without the control of its owner instance (goodbye encapsulation). From the Findbugs' bug descriptions:
If such exposition comes from a hand crafted code, you can blame
the developer or even use some code quality metric to avoid that kind of
risk comes out to the release. But what to do when it comes from an
automatic process? Well, that's what happens when you unmarshal
Compiling your own byte array TrojanOk, it can be excess of paranoia, but if you compile a schema
containing elements defined as base64Binary, JAXB will compile it as XSD fragment:
<xsd:complexType name="ImageAttachment">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" />
<xsd:element name="flash" type="xsd:base64Binary"
mime:expectedContentTypes="application/x-shockwave-flash" />
</xsd:sequence>
</xsd:complexType>
JAXB 2.0 generated class fragment:
public class ImageAttachment
{
protected byte[] flash;
public byte[] getFlash() {
return flash;
}
public void setFlash(byte[] value) {
this.flash = ((byte[]) value);
}
}
WorkaroundHere are the few workarounds I assume reasonable to adopt in such situation:
So far this is the only one bug pointed by Findbugs over my project, so I prefer to keep the warning alive in in my quality reports, in the hope to find an elegant solution for that. Perhaps you know how to fix that :) »
Related Topics >>
Java Web Services and XML Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|