Issue
I have a situation where the one of the JVM options, the "-D" flag is large, over 1000 characters. Is there a limit how large this value can be?
-Dhttp.nonProxyHosts=localhost|127.0.0.1|169.254.169.254|162.31.160.0/20|100.77.147.160/27|100.77.163.160/27|100.77.179.160/27|162.18.168.0/23|162.18.170.0/23|162.18.172.0/23|10.100.0.0/16|.internal|.foobr.com|.execute-api.us-west-2.amazonaws.com|.s3.us-west-2.amazonaws.com|.us-west-2.eks.amazonaws.com|.us-west-2.vpce.amazonaws.com|amazonlinux.us-west-2.amazonaws.com|api.sagemaker.us-west-2.amazonaws.com|cloudformation.us-west-2.amazonaws.com|cloudtrail.us-west-2.amazonaws.com|codebuild-fips.us-west-2.amazonaws.com|codebuild.us-west-2.amazonaws.com|config.us-west-2.amazonaws.com|dynamodb.us-west-2.amazonaws.com|ec2.us-west-2.amazonaws.com|ec2messages.us-west-2.amazonaws.com|elasticloadbalancing.us-west-2.amazonaws.com|events.us-west-2.amazonaws.com|kinesis.us-west-2.amazonaws.com|kms.us-west-2.amazonaws.com|logs.us-west-2.amazonaws.com|monitoring.us-west-2.amazonaws.com|runtime.sagemaker.us-west-2.amazonaws.com|secretsmanager.us-west-2.amazonaws.com|servicecatalog.us-west-2.amazonaws.com|sns.us-west-2.amazonaws.com|ssm.us-west-2.amazonaws.com|ssmmessages.us-west-2.amazonaws.com|sts.us-west-2.amazonaws.com
Solution
Yes and no. It's complicated. But mostly good news.
- java does not care; the args are passed in as a string, though (and not as a stream from disk), which means there is a limit based on your memory. But, 1 GB's worth of text is... a lot of -D options. A few orders of magnitude more than you currently have.
- The shell and the OS, however, certainly do. Windows, for example, cannot run commands that exceed 8191 characters in length. You're currently on ~1200 characters, so you can make your -D stuff about 7x longer than what you have right now, but then you're done, at least on windows. On posix it's dependent on OS and shell, but there are usually also limits.
getconf ARG_MAX
usually tells you what it is. On my desktop system it's currently 1048576, on a random linux shell i have access to, it's 2097152. That's a ton of room to grow for you. - You can avoid all problems by using the
@
system. You can writejava @foo.txt
, which will cause the java executable to openfoo.txt
and use the contents of this file as arguments. So, put your giant -D switch in a file, and then use@allThatJazz.txt
instead of-Dreallylongcommandlineoption
. Now you can stop caring about OS imposed args limits. - Given that -D switches are available via
System.getProperty
, your limit is now heap related. We're talking hundreds of megabytes before it becomes unwieldy - 200,000,000 characters maybe.
Answered By - rzwitserloot
Answer Checked By - Pedro (JavaFixing Volunteer)