yogendra-aurospaces / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

Joiner.join would benefit from accepting null #176

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I often use the Joiner.join method to combine objects for debugging output. I 
can't guarantee 
that the objects will not be null. If any object is null, a NPE is received 
from join. It would be 
great if nulls were handled in 1.0 e.g. print "(null)" or "null".

import com.google.common.base.Joiner;
import static java.lang.System.out;

public class Scratch {

    public static final void main(String[] args) {
        out.println(Joiner.on("").join("hello", null));
    }
}

Original issue reported on code.google.com by Sam.Hall...@gmail.com on 29 May 2009 at 2:02

GoogleCodeExporter commented 9 years ago
Just read the docs... this is a DEFECT. The docs say join is @Nullable

Original comment by Sam.Hall...@gmail.com on 29 May 2009 at 2:03

GoogleCodeExporter commented 9 years ago
OK, just read the Class documentation and note that this is expected behaviour. 
Apologies.

However, I must admit... given that the parameters are @Nullable, this is 
highly unexpected! I strongly 
recommend that the default behaviour be to print "null" when nulls are detected.

Original comment by Sam.Hall...@gmail.com on 29 May 2009 at 2:06

GoogleCodeExporter commented 9 years ago
The Joiner.useForNull method provides the functionality you're requesting.

Original comment by jared.l....@gmail.com on 29 May 2009 at 4:56