Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3998660
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:33:14+00:00 2026-05-20T07:33:14+00:00

Out of curiosity I tried to create a really large string. It turned out

  • 0

Out of curiosity I tried to create a really large string. It turned out that the Formatter class chokes on width specifications exceeding Integer.MAX_VALUE:

// Produces an empty string. (2147483648 = Integer.MAX_VALUE + 1)
String.format("%2147483648s", "");

So I went off to verify that it was indeed according to spec. But all it says is

If the format specifier contains a width or precision with an invalid value or which is otherwise unsupported, then a IllegalFormatWidthException or IllegalFormatPrecisionException respectively will be thrown.

So in my opinion the correct behavior would be to throw an IllegalFormatWidthException.

Is this bug (?) documented somewhere? (If not, I’ll go report it.)


Also, it should be noted that if one puts a - in front of the width (to left-justify the output):

String.format("%-2147483648s", "");

it indeed throws a MissingFormatWidthException (which, as I see it, seems to be correct behavior).

(I’m using OpenJDK version 1.6.0_20.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:33:15+00:00Added an answer on May 20, 2026 at 7:33 am

    I think you’re right and that it’s a bug: it should throw IllegalFormatWidthException, if any existing exception.

    The javadoc for that exception says “Unchecked exception thrown when the format width is a negative value other than -1 or is otherwise unsupported”, which oddly doesn’t specifically mention values that are too large. I think the “otherwise unsupported” clause makes this a reasonable exception to throw.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just out of curiosity I tried overriding a abstract method in base class, and
Out of curiosity, why are sometimes multiple Java .class files generated for a class
Out of curiosity is it possible to temporarily add a character that should be
Out of curiosity, I'd like to know if anyone knows of any somewhat large
Just for the curiosity I tried this: public interface test1 { public Object method1(String
Out of curiosity i disassembled mscorlib.dll to check the implementation of System.Object class. I
Today out of curiosity, i tried something very weird: The Code : int num
I'm looking for a way to create a class that has a default public
out of sheer curiosity I tried compiling a 2.6.0 kernel on my slackware machine.
This is a question just out of curiosity. I know that when we call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.