Checker CallsOnArray   as of Julia version 2.4 (built on 23 Oct 2017)

belongs to group Basic

Identify suspicious calls over arrays

Arrays are instances of java.lang.Object in Java. As a consequence, all methods of java.lang.Object can be invoked on arrays, However, this is not always sensible. In particular, calls to toString() yield a string derived from the unique identifier of the object, which is likely to be useless for the programmer and not her intent when she called toString().

It is possible that this warning is the consequence of refactoring, that replaced a collection class with an array but left the method calls unchanged.

Action: Replace the call with a call to java.util.Arrays.toString(array) or with an explicit iteration over the elements of the array.


Consider the following program:

public class CallsOnArray {
  private static A[] array;

  public static void main(String[] args) {
    array = new A[args.length];
    for (int pos = 0; pos < args.length; pos++)
      array[pos] = new A(args[pos]);



  public static void foo(Object o) {
    String s = o.toString();

  private static class A {
    private int f;

    private A(String s) {
      this.f = s.length();

    public String toString() {
      return String.valueOf(f);

This checker issues the following warnings: [CallsOnArray: CallToToStringOnArrayWarning] Call to toString() on array [CallsOnArray: CallToToStringOnArrayWarning] Call to toString() on array

At line 11, the array is passed to the println() method, that will invoke onString() on it. At line 15, the call to println() is direct and Julia recognizes that an array is passed for o, although its static type is java.lang.Object.

In this example, the programmer should probably replace line 11 with the loop:

for (int pos = 0; pos < array.length; pos++)

or similar.