Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35897

Re: java.net.URLEncoder.encode + UTF-8 (rant)

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: java.net.URLEncoder.encode + UTF-8 (rant)
Date 2016-11-14 14:45 -0500
Organization A noiseless patient Spider
Message-ID <o0d47k$5p0$1@dont-email.me> (permalink)
References <slrno09hi9.456.avl@login.logic.tuwien.ac.at> <o0d1tp$sft$1@dont-email.me>

Show all headers | View raw


On 11/14/2016 2:05 PM, Daniele Futtorovic wrote:
> On 2016-10-17 14:38, Andreas Leitgeb wrote:
>> <rant target="java.net.URLEncoder.encode(String s, String enc)">
>>
>> This method should (according to the w3c) only be used with UTF-8
>> and UTF-8 is always supposed to be supported by Java.
>>
>> Why is there no java.net.URLEncoder.encodeUTF8(String s) that
>> would free me from that boring
>>   try {...} catch (UnsupportedEncodingException ign) {...}
>> boilerplate?  (What code do good(tm) Java programmers even put
>> into this catch clause, that is expected to never run, anyway?)
>
> throw new AssertionError( ing.toString() );

     In situations like this, I think

	throw new AssertionError("BUG!", ign);

is marginally better in that it preserves all the information from
the "cannot happen" exception instead of only its message text.  (If
you ever catch a "cannot happen" exception something very odd must
have happened, and if something *that* odd happens you'll be glad of
every possible clue ...)

> But yeah, it's annoying.

     Yes.  Sometimes, anyhow.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

java.net.URLEncoder.encode + UTF-8 (rant) Andreas Leitgeb <avl@logic.at> - 2016-10-17 12:38 +0000
  Re: java.net.URLEncoder.encode + UTF-8 (rant) j4n bur53 <janburse@fastmail.fm> - 2016-10-17 16:55 +0200
  Re: java.net.URLEncoder.encode + UTF-8 (rant) Arne Vajhøj <arne@vajhoej.dk> - 2016-10-19 21:35 -0400
  Re: java.net.URLEncoder.encode + UTF-8 (rant) Daniele Futtorovic <da.futt.news@laposte.net> - 2016-11-14 20:05 +0100
    Re: java.net.URLEncoder.encode + UTF-8 (rant) Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-11-14 14:45 -0500

csiph-web