public T addFromMandatoryProperty(Props props, String propertyName) {
    String value = props.nonNullValue(propertyName);
    if (!value.isEmpty()) {
      String splitRegex = " (?=-)";
      List<String> jvmOptions = Arrays.stream(value.split(splitRegex)).map(String::trim).toList();
      checkOptionFormat(propertyName, jvmOptions);
      checkMandatoryOptionOverwrite(propertyName, jvmOptions);
      options.addAll(jvmOptions);
    }

    return castThis();
  }
@Test
  public void addFromMandatoryProperty_throws_IAE_if_option_starts_with_prefix_of_mandatory_option_but_has_different_value() {
    String[] optionOverrides = {
      randomPrefix,
      randomPrefix + randomValue.substring(1),
      randomPrefix + randomValue.substring(1),
      randomPrefix + randomValue.substring(2),
      randomPrefix + randomValue.substring(3),
      randomPrefix + randomValue.substring(3) + randomAlphanumeric(1),
      randomPrefix + randomValue.substring(3) + randomAlphanumeric(2),
      randomPrefix + randomValue.substring(3) + randomAlphanumeric(3),
      randomPrefix + randomValue + randomAlphanumeric(1)
    };

    JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue));

    for (String optionOverride : optionOverrides) {
      try {
        properties.put(randomPropertyName, optionOverride);
        underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName);
        fail("an MessageException should have been thrown");
      } catch (MessageException e) {
        assertThat(e.getMessage())
          .isEqualTo("a JVM option can't overwrite mandatory JVM options. " +
            "The following JVM options defined by property '" + randomPropertyName + "' are invalid: " + optionOverride + " overwrites " + randomPrefix + randomValue);
      }
    }
  }