senyor / generate-tostring

Automatically exported from code.google.com/p/generate-tostring
0 stars 0 forks source link

Wrong toString() generation when there are promitive arrays as fields #25

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
>> What steps will reproduce the problem?

1. Create a class:
public class Vector {
    private double[] values;
}

2. Alt+Ins, then toString(), then we see

>> What is the expected output? 

Something like this, which works:

public class Vector {
    private double[] values;

    @Override
    public String toString() {
        return "Vector{" +
                "values=" + (values == null ? null :
Arrays.toString(values)) + '}';
    }
}

>> What do you see instead?

import java.util.Arrays;

public class Vector {
    private double[] values;

    @Override
    public String toString() {
        return "Vector{" +
                "values=" + (values == null ? null : Arrays.asList(values))
+ '}';
    }
}

which is wrong because Arrays.asList does not work as expected on primitive
arrays (it is a vararg method).

>> What version of the product are you using? On what operating system?

The one that is shipped with IntelliJ IDEA 8.1. Linux.

Please provide any additional information below.

Suppose to replace Arrays.asList with Arrays.toString. It doesn't create a
list object and correctly works with nulls.

Original issue reported on code.google.com by mbuzda...@gmail.com on 26 Apr 2009 at 11:44

GoogleCodeExporter commented 8 years ago
Sorry for mistakes,
promitive -> primitive
suppose -> suggest

Original comment by mbuzda...@gmail.com on 26 Apr 2009 at 11:51

GoogleCodeExporter commented 8 years ago
Good idea, I think changing the template provided out of the box is all what is 
needed.

Original comment by claus.ib...@gmail.com on 26 Dec 2009 at 4:00