You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] OptimizableToArrayCall: False positive when new T[0x0] is used instead of new T[0] #6740
PMD's OptimizableToArrayCall rule recommends calling collection.toArray(new T[0]) over a pre-sized array such as collection.toArray(new T[collection.size()]). The zero-length form is explicitly whitelisted as compliant.
The rule decides whether the supplied array is "zero-sized" by matching the lexical image of the size literal against the string "0", rather than its numeric value. As a result, a hexadecimal zero literal 0x0 — which is numerically and at runtime identical to 0 — is not recognized as a zero-sized array, and the rule raises a false positive on collection.toArray(new T[0x0]).
new String[0] and new String[0x0] denote the same int constant 0 and allocate the same zero-length array. The two snippets are runtime-equivalent.
Expected behavior:
OptimizableToArrayCall should treat new T[0x0] exactly like new T[0] and produce no finding, because both express a zero-sized array. The whitelist should compare the literal's numeric value, not its lexical spelling.
Actual behavior:
new String[0] → 0 findings (correct).
new String[0x0] → 1 finding: This call to Collection.toArray() may be optimizable on the toArray call, even though the array is already zero-sized.
The rule's verdict is sensitive to the literal's textual form (0 vs 0x0) rather than its value. Other equivalent spellings such as 00, 0L cast, or 0_0 are likely affected for the same reason.
changed the title [-][java] FP: OptimizableToArrayCall flags `new T[0x0]` as optimizable even though `0x0` is a zero-sized array[/-][+][java] OptimizableToArrayCall: False positive when `new T[0x0]` is used instead of `new T[0]`[/+]on Jun 4, 2026
Activity
[-][java] FP: OptimizableToArrayCall flags `new T[0x0]` as optimizable even though `0x0` is a zero-sized array[/-][+][java] OptimizableToArrayCall: False positive when `new T[0x0]` is used instead of `new T[0]`[/+][java] Fix #6740: Fix FP in OptimizableToArrayCall (#6813)
Fix pmd#6740: Use value of NumericLiteral, not String representation