MethodReturnsInternalArray: False positive using a ternary operator
A source code analyzer
Brought to you by:
adangel,
juansotuyo
Suppose you have a POJO that contains a method like that:
public byte[] getContent() {
return this.content == null ? null : content.clone();
}
This does a defensive copy but the PMD raises the following issue:
Returning 'content' may expose an internal array
When I change the method to something like:
public byte[] getContent() {
if(content != null) {
return content.clone();
}
return null;
}
This doesn't raise any warning
Would it raise a warning if you did something like:
public byte[] getContent() {
if(content == null) {
return null;
}
return content.clone();
}
Already fixed.