How can I avoid IllegalArgumentException of MapSpitter.

150 views
Skip to first unread message

jan.winte...@gmail.com

unread,
Nov 26, 2014, 5:02:30 AM11/26/14
to guava-...@googlegroups.com
Hello all,

I get a IllegalArgumentException if I do this:

    MapSplitter splitter = Splitter//
        .on(";")//
        .withKeyValueSeparator("=");

    Assert.assertNotNull(splitter.split("key=value;key2=value"));
    /* throw Exception */splitter.split("key=value;key2=value=");

It is possible to setup the MapSplitter to get a map like:

{key=value, key2=value=} 

instead of IllegalArgumentException.

Thanks Regards, 

Jan

Louis Wasserman

unread,
Nov 26, 2014, 9:48:55 AM11/26/14
to jan.winte...@gmail.com, guava-...@googlegroups.com
Under what circumstances would an input like that be valid, and not an indication that there's a bug in your input data?

I don't believe there's any way to make that input allowed, just because it's ambiguous input: it could arguably be read as either "key2" mapped to "value=", or "key2=value" mapped to "".

--
guava-...@googlegroups.com
Project site: https://github.com/google/guava
This group: http://groups.google.com/group/guava-discuss
 
This list is for general discussion.
To report an issue: https://github.com/google/guava/issues/new
To get help: http://stackoverflow.com/questions/ask?tags=guava
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/0d23e551-90f4-4d8e-b367-88c4058ea871%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Grajcar

unread,
Nov 26, 2014, 11:16:36 AM11/26/14
to Louis Wasserman, jan.winte...@gmail.com, guava-discuss
On Wed, Nov 26, 2014 at 3:48 PM, 'Louis Wasserman' via guava-discuss <guava-...@googlegroups.com> wrote:
Under what circumstances would an input like that be valid, and not an indication that there's a bug in your input data?

I don't believe there's any way to make that input allowed, just because it's ambiguous input: it could arguably be read as either "key2" mapped to "value=", or "key2=value" mapped to "".

Maybe, but usually keys contain no special chars while values are unrestricted. See also java.util.Properties:

The key contains all of the characters in the line starting with the first non-white space character and up to, but not including, the first unescaped '='':', or white space character other than a line terminator.

Escaping, colon, and whitespace are a different story, but without them, the key ends with the first equal sign. Stopping at the first separator is a common practice, albeit sloppy.

David Beaumont

unread,
Nov 26, 2014, 2:20:31 PM11/26/14
to Martin Grajcar, Louis Wasserman, jan.winte...@gmail.com, guava-discuss
I think that it's not unreasonable to want arbitrary text in values after the first separator.
Many of the common text based key/value formats do this.

Cheers,
    David

--
guava-...@googlegroups.com
Project site: https://github.com/google/guava
This group: http://groups.google.com/group/guava-discuss
 
This list is for general discussion.
To report an issue: https://github.com/google/guava/issues/new
To get help: http://stackoverflow.com/questions/ask?tags=guava
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/CAGsWfGixQHQO3TyOpomyeH%3DO1CvX9dkgberFiARUNfHAjjyOJw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
David Beaumont :: Îñţérñåţîöñåļîžåţîờñ Libraries :: Google
Google Switzerland GmbH., Brandschenkestrasse 110, CH-8002, Zürich - Switzerland
Tel +41 44 668 1800 :: Fax +41 44 668 1818
Reply all
Reply to author
Forward
0 new messages