Repository: wiremock/wiremock (2025-08-08T19:27:18Z)

Issue:
Global --timeout CLI option parser broken
### Proposal

Attempting to set `--timeout 5000` CLI option and making a request results in a `Error 500 java.lang.NumberFormatException: null` (Cannot parse null string) error.

### Reproduction steps

```java
  @Test
  public void returnsCorrectlyParsedGlobalTimeout() {
    CommandLineOptions options = new CommandLineOptions("--timeout", "45000");
    assertThat(options.timeout(), is(45_000L));
  }
```

### References

_No response_


Discussion:

Patch:
diff --git a/src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java b/src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java
index 24467b787b..e855a6b6dc 100644
--- a/src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java
+++ b/src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java
@@ -160,7 +160,7 @@ public CommandLineOptions(String... args) {
         .withRequiredArg();
     optionParser.accepts(BIND_ADDRESS, "The IP to listen connections").withRequiredArg();
     optionParser.accepts(CONTAINER_THREADS, "The number of container threads").withRequiredArg();
-    optionParser.accepts(TIMEOUT, "The default global timeout.");
+    optionParser.accepts(TIMEOUT, "The default global timeout in milliseconds.").withRequiredArg();
     optionParser.accepts(
         DISABLE_OPTIMIZE_XML_FACTORIES_LOADING,
         "Whether to disable optimize XML factories loading or not.");
@@ -916,7 +916,7 @@ public boolean getStubCorsEnabled() {
 
   @Override
   public long timeout() {
-    return optionSet.has(TIMEOUT)
+    return optionSet.hasArgument(TIMEOUT)
         ? Long.parseLong((String) optionSet.valueOf(TIMEOUT))
         : DEFAULT_TIMEOUT;
   }


Test patch:
diff --git a/src/test/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptionsTest.java b/src/test/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptionsTest.java
index 598c429f53..032af59c68 100644
--- a/src/test/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptionsTest.java
+++ b/src/test/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptionsTest.java
@@ -328,6 +328,18 @@ public void defaultsContainerThreadsTo25() {
     assertThat(options.containerThreads(), is(25));
   }
 
+  @Test
+  public void returnsCorrectlyParsedGlobalTimeout() {
+    CommandLineOptions options = new CommandLineOptions("--timeout", "45000");
+    assertThat(options.timeout(), is(45_000L));
+  }
+
+  @Test
+  public void returnsDefaultGlobalTimeout() {
+    CommandLineOptions options = new CommandLineOptions();
+    assertThat(options.timeout(), is(300_000L));
+  }
+
   @Test
   public void returnsCorrectlyParsedJettyAcceptorThreads() {
     CommandLineOptions options = new CommandLineOptions("--jetty-acceptor-threads", "400");