public static void validateJvmOpts(String jvmOpts)
      throws IllegalArgumentException {
    Pattern pattern = Pattern.compile("[!~#?@*&%${}()<>\\[\\]|\",`;]");
    Matcher matcher = pattern.matcher(jvmOpts);
    if (matcher.find()) {
      throw new IllegalArgumentException(
          RestApiErrorMessages.ERROR_JVM_OPTS);
    }
  }
@Test
  public void testJvmOpts() throws Exception {
    String invalidJvmOpts = "`ping -c 3 example.com`";
    intercept(IllegalArgumentException.class,
        "Invalid character in yarn.service.am.java.opts.",
        () -> ServiceApiUtil.validateJvmOpts(invalidJvmOpts));
    String validJvmOpts = "-Dyarn.service.am.java.opts=-Xmx768m "
        + "-Djava.security.auth.login.config=/opt/hadoop/etc/jaas-zk.conf";
    try {
      ServiceApiUtil.validateJvmOpts(validJvmOpts);
    } catch (Exception ex) {
      fail("Invalid character in yarn.service.am.java.opts.");
    }
  }