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


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

Re: What happens when format gets a wrong argument

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: What happens when format gets a wrong argument
Date 2016-08-19 20:19 -0400
Organization Aioe.org NNTP Server
Message-ID <np87m7$d71$1@gioia.aioe.org> (permalink)
References <87eg5lkd05.fsf@Equus.decebal.nl> <np59f7$vj5$1@dont-email.me> <np5fub$ai1$2@gioia.aioe.org> <np6tm2$j64$1@dont-email.me>

Show all headers | View raw


On 8/19/2016 8:22 AM, Eric Sosman wrote:
> On 8/18/2016 7:21 PM, Arne Vajhøj wrote:
>> On 8/18/2016 5:31 PM, Eric Sosman wrote:
>>> On 8/18/2016 5:01 PM, Cecil Westerhof wrote:
>>>> I had a function in ScheduledExecutorService where I changed a
>>>> parameter for format from long to double, but I forgot to change the
>>>> format string. The result was that the function gets an unchecked
>>>> IllegalFormatConversionException and silently terminated on the format
>>>> statement. Is this normal? And where do I find a good description
>>>> about this?
>>>
>>>     It's normal.  Java's printf-inspired format strings are not quite
>>> as good as C's, because C compilers (by and large) are able to sanity-
>>> check the formats at compile time while JavaC doesn't (yet, anyhow).
>>
>> The C way is extremely practical/useful.
>>
>> But it is a bit mixing compiler and library responsibility. It
>> must be a hardcoded special case in the compiler.
>
>     Yes.  I don't see why javac could not have similar special
> cases, but it doesn't.  (They'd be subject to similar limitations,
> too, but I think even an imperfect job would be better than none.)
>
>     As for "mixing responsibility" -- well, there's already plenty
> of precedent in Java for the language to have "special knowledge" of
> the class library.  The compiler rejects `throw "error";', thus
> revealing special knowledge of `Throwable'.  The compiler knows
> about `StringBuilder', and relies upon it for "language" features.
> The compiler knows enough about the class library to do automatic
> generation of `Integer.valueOf(n)' and `theDouble.doubleValue()'
> and the like.  It does not seem to me that adding knowledge of
> `Formatter' would amount to a violation of purity -- there would be
> practical difficulties, yes, but no loss of innocence.

Using certain library functions in the generated code is not as
dirty as checking the content of a string constant.

But it would be OK for me. I am just trying to explain
why it may not have been so obvious to implement.

Arne



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


Thread

What happens when format gets a wrong argument Cecil Westerhof <Cecil@decebal.nl> - 2016-08-18 23:01 +0200
  Re: What happens when format gets a wrong argument Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-18 17:31 -0400
    Re: What happens when format gets a wrong argument Arne Vajhøj <arne@vajhoej.dk> - 2016-08-18 19:21 -0400
      Re: What happens when format gets a wrong argument Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-19 08:22 -0400
        Re: What happens when format gets a wrong argument Gene Wirchenko <genew@telus.net> - 2016-08-19 10:40 -0700
        Re: What happens when format gets a wrong argument Arne Vajhøj <arne@vajhoej.dk> - 2016-08-19 20:19 -0400
  Re: What happens when format gets a wrong argument Cecil Westerhof <Cecil@decebal.nl> - 2016-08-19 01:25 +0200
  Re: What happens when format gets a wrong argument Arne Vajhøj <arne@vajhoej.dk> - 2016-08-18 19:31 -0400
  Re: What happens when format gets a wrong argument Arne Vajhøj <arne@vajhoej.dk> - 2016-08-18 19:35 -0400
    Re: What happens when format gets a wrong argument Cecil Westerhof <Cecil@decebal.nl> - 2016-08-19 07:23 +0200

csiph-web