sta-szek / pojo-tester

Java testing framework for testing pojo methods. It tests equals, hashCode, toString, getters, setters, constructors and whatever you report in issues ;)
http://www.pojo.pl
GNU Lesser General Public License v3.0
53 stars 26 forks source link

Object[] property causing: has bad 'toString' method implementation in Intellij #235

Open raspacorp opened 5 years ago

raspacorp commented 5 years ago

There is already a similar issue about Intellij IDEA generated toString, however that one is very specific about a String property, so I opted to create a new one for this:

public class SearchResult
{
    private final Object[] lastRecordSortValues;
    private final int pageTotal;

    public Object[] getLastRecordSortValues()
    {
        return lastRecordSortValues;
    }

    public int getPageTotal()
    {
        return pageTotal;
    }

    @Override
    public boolean equals(final Object o)
    {
...
    }

    @Override
    public int hashCode()
    {
...
    }

    @Override
    public String toString()
    {
        return "SearchResult{" +
                "lastRecordSortValues=" + Arrays.toString(lastRecordSortValues) +
                ", pageTotal=" + pageTotal +
                '}';
    }
}

It seems it dislikes this: lastRecordSortValues=" + Arrays.toString(lastRecordSortValues)

This is the full message I get:

Class com.myapp.SearchResult has bad 'toString' method implementation.
The toString method should contain:
lastRecordSortValues=[Ljava.lang.Object;@26f09a1c
But does not.
Result of toString:
SearchResult{lastRecordSortValues=[], pageTotal=0}