Affects PMD Version: tbd
Rule: MethodReturnsInternalArray, https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#methodreturnsinternalarray
Description: Static final fields are currently ignored as per https://sourceforge.net/p/pmd/bugs/1475/. However, this is only safe because the array has length zero. Sharing non-empty arrays is problematic whether the field is final or not, so it doesn't make sense to forbid one and allow the other.
Code Sample demonstrating the issue:
public class MyClass {
private static final String[] FOO_BAR = new String[] { "foo", "bar" };
public String[] call() { return FOO_BAR; }
}
Second example:
public class MyClass {
private String[] fooBar = new String[0];
public String[] call() { return fooBar; }
}
Expected outcome: A violation should be reported on the first example
Affects PMD Version: tbd
Rule: MethodReturnsInternalArray, https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#methodreturnsinternalarray
Description: Static final fields are currently ignored as per https://sourceforge.net/p/pmd/bugs/1475/. However, this is only safe because the array has length zero. Sharing non-empty arrays is problematic whether the field is final or not, so it doesn't make sense to forbid one and allow the other.
Code Sample demonstrating the issue:
Second example:
Expected outcome: A violation should be reported on the first example