{"record":{"id":"2bce2e5c9a4753c5","repo":"bazelbuild/bazel","slug":"no-filter-expression-specified-after-arg","errorCode":null,"errorMessage":"No filter expression specified after ${arg}","messagePattern":"No filter expression specified after (.+?)","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Options.java","lineNumber":66,"sourceCode":"    Map<String, String> optionsMap = new HashMap<>();\n\n    optionsMap.put(TEST_INCLUDE_FILTER_OPTION, null);\n    optionsMap.put(TEST_EXCLUDE_FILTER_OPTION, null);\n\n    for (Iterator<String> it = args.iterator(); it.hasNext();) {\n      String arg = it.next();\n      int indexOfEquals = arg.indexOf(\"=\");\n\n      if (indexOfEquals > 0) {\n        String optionName = arg.substring(0, indexOfEquals);\n        if (optionsMap.containsKey(optionName)) {\n          optionsMap.put(optionName, arg.substring(indexOfEquals + 1));\n          continue;\n        }\n      } else if (optionsMap.containsKey(arg)) {\n        // next argument is the regexp\n        if (!it.hasNext()) {\n          throw new RuntimeException(\"No filter expression specified after \" + arg);\n        }\n        optionsMap.put(arg, it.next());\n        continue;\n      }\n      unparsedArgs.add(arg);\n    }\n    // If TESTBRIDGE_TEST_ONLY is set in the environment, forward it to the\n    // --test_filter flag.\n    String testFilter = envVars.get(TESTBRIDGE_TEST_ONLY);\n    if (testFilter != null && optionsMap.get(TEST_INCLUDE_FILTER_OPTION) == null) {\n      optionsMap.put(TEST_INCLUDE_FILTER_OPTION, testFilter);\n    }\n    boolean testRunnerFailFast = \"1\".equals(envVars.get(TESTBRIDGE_TEST_RUNNER_FAIL_FAST));\n    return new JUnit4Options(\n        testRunnerFailFast,\n        optionsMap.get(TEST_INCLUDE_FILTER_OPTION),\n        optionsMap.get(TEST_EXCLUDE_FILTER_OPTION),\n        unparsedArgs.toArray(new String[0]));","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Options.java#L48-L84","documentation":"Thrown by JUnit4Options.parseArgs when a filter option that expects a separate value argument (e.g. --test_filter or --test_exclude_filter) is the last token on the command line. The parser sees the option name, calls it.next() to read the regular expression, and finds no more arguments, so it throws a RuntimeException rather than silently ignoring the filter.","triggerScenarios":"Invoking JUnit4Options.parseArgs(args, envVars) with args ending in \"--test_filter\" (or another space-separated option key) with no following value, e.g. args = [\"--test_filter\"].","commonSituations":"Shell scripts or bazel run invocations that build the filter from a variable which expands to empty at the end of the line (RUNNER_ARGS=\"--test_filter $FILTER\" with FILTER unset); typo'd flag split across lines in CI config.","solutions":["Use the equals form so the value is part of the token: --test_filter=com.foo.MyTest#method.","If the value comes from a variable, guard it so the flag is only appended when the variable is non-empty.","Pass the filter via the TESTBRIDGE_TEST_ONLY environment variable instead, which the runner forwards to --test_filter when no explicit filter is present."],"exampleFix":"# before\njava ... JUnit4Runner --test_filter $TESTS   # TESTS empty -> flag dangles\n# after\nFILTER=${TESTS:+--test_filter=$TESTS}\njava ... JUnit4Runner $FILTER","handlingStrategy":"validation","validationCode":"// before JUnit4Options.parseArgs\nfor (int i = 0; i < args.length; i++) {\n  if (args[i].equals(\"--test_filter\") || args[i].equals(\"--test_exclude_filter\")) {\n    if (i + 1 >= args.length || args[i + 1].startsWith(\"--\")) {\n      throw new IllegalArgumentException(\"Missing value for \" + args[i]);\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  JUnit4Options.parseArgs(Arrays.asList(args), env);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"No filter expression\")) { /* surface usage error */ }\n}","preventionTips":["Prefer the --flag=value form for all junitrunner filter flags.","Build argument lists conditionally: only append --test_filter when the variable is non-empty.","Use TESTBRIDGE_TEST_ONLY for externally supplied filters."],"tags":["junit","bazel","command-line","argument-parsing"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}