0

I had a method which generated the PMD violation ArrayIsStoredDirectly:

public void setFoo(Object[] foo) {
    this.foo = foo;
}

This is understandable - I need to clone the array. So I replaced it with:

public void setFoo(Object[] foo) {
    if (foo == null) {
        this.foo = null;
    } else {
        this.foo = new Object[foo.length];
        System.arraycopy(foo, 0, this.foo, 0, foo.length);
    }
}

However, I'm still getting the ArrayIsStoredDirectly violation!

I'm really not sure why this is. Maybe something in the ArrayIsStoredDirectly class is still being picked up incorrectly?

I know I could just suppress the warning, but this doesn't seem like too much of a special case. What is the correct way to fix this violation?

Adam Burley
  • 5,551
  • 4
  • 51
  • 72

0 Answers0