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


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

Re: What happens when format gets a wrong argument

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: What happens when format gets a wrong argument
Date Thu, 18 Aug 2016 17:31:06 -0400
Organization A noiseless patient Spider
Lines 26
Message-ID <np59f7$vj5$1@dont-email.me> (permalink)
References <87eg5lkd05.fsf@Equus.decebal.nl>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Thu, 18 Aug 2016 21:31:20 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="32357"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QRrMVqYZLPh6guS3ZzEOq"
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
In-Reply-To <87eg5lkd05.fsf@Equus.decebal.nl>
Cancel-Lock sha1:gdDs5kkajySdYpJGdvtRb17BTZw=
Xref csiph.com comp.lang.java.programmer:35395

Show key headers only | View raw


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).

     For a description, see the JavaDoc for java.util.Formatter, which
says (near the top) "[...] Java formatting is more strict than C's; for
example, if a conversion is incompatible with a flag, an exception will
be thrown."  (It also says "In C inapplicable flags are silently
ignored," which is wrong -- but inability to comprehend C is to be
expected from Java folks, who can't even grok "unsigned.")

> Is there a way to get things automatically logged?

     Don't make misteaks?  :(

-- 
esosman@comcast-dot-net.invalid
The Tooth Fairy has gone high-tech, now pays in Bitecoin.

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