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


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

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

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: java.net.URLEncoder.encode + UTF-8 (rant)
Date 2016-10-19 21:35 -0400
Organization Aioe.org NNTP Server
Message-ID <nu9705$f18$1@gioia.aioe.org> (permalink)
References <slrno09hi9.456.avl@login.logic.tuwien.ac.at>

Show all headers | View raw


On 10/17/2016 8:38 AM, 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?)
>
> Other JSL methods dealing with encodings at least let me specify the
> encoding as an instance of Charset, so I can pass StandardCharsets.UTF_8
> there and be safe against typos leading to an exception at runtime -
> one, whose only fix would be correcting the source.
>
> For URLEncoder it would even make sense to "re-precate" the plain
> encoding(String s) to always use UTF-8 instead of native encoding.
> It surely would fix more ancient applications than it would break.
>
> </rant>

There is probably a lot of convenience methods that would be nice
to have for some people.

Traditionally Java has been behind regarding such.

I think Java 7 and 8 actually did introduce some such.

But apparently they have not gotten to this one yet. Or maybe
they have and decided it was not important enough. There is
so much stuff that could be added - prioritization is a must.

Arne

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next 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