Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: What happens when format gets a wrong argument Date: Fri, 19 Aug 2016 08:22:12 -0400 Organization: A noiseless patient Spider Lines: 37 Message-ID: References: <87eg5lkd05.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 19 Aug 2016 12:22:26 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="22e5ab429c5a4bb738666b9c52e40d69"; logging-data="19652"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/L+LUWAFjXQrZcn6YQDoy" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: Cancel-Lock: sha1:OOHsHgqegOZE6S766A25FVs2C6o= Xref: csiph.com comp.lang.java.programmer:35407 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. -- esosman@comcast-dot-net.invalid The Tooth Fairy has gone high-tech, now pays in Bitecoin.