Menu

#962 MethodReturnsInternalArray: False positive using a ternary operator

PMD-5.0.3
not-reproducible
pmd (543)
PMD
3-Major
Bug
2013-04-05
2011-03-17
Bruno Barin
No

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

Related

Issues: #1324

Discussion

  • Steven Christou

    Steven Christou - 2011-04-14

    Would it raise a warning if you did something like:

    public byte[] getContent() {

    if(content == null) {
    return null;
    }

    return content.clone();
    }

     
  • Andreas Dangel

    Andreas Dangel - 2013-03-16

    Already fixed.

     
  • Andreas Dangel

    Andreas Dangel - 2013-03-16
    • summary: False positive using a ternary operator --> MethodReturnsInternalArray: False positive using a ternary operator
    • status: open --> not-reproducible
    • assigned_to: Tom Copeland --> Andreas Dangel
    • module: --> PMD
    • milestone: --> PMD-5.0.3
    • priority: 5 --> 3-Major
    • type: --> Bug
    • affects_version: -->
     

Log in to post a comment.