brettwooldridge/HikariCP · error · IllegalArgumentException

Unterminated escape sequence in property value: %s

Error message

Unterminated escape sequence in property value: %s

What it means

PropertyElf's property splitter supports escaped separators/escape characters in comma-separated values (e.g. data source property lists). If a value ends while an escape is still open (trailing backslash), the unterminated escape throws IllegalArgumentException.

Source

Thrown at src/main/java/com/zaxxer/hikari/util/PropertyElf.java:239

      for (var c : value.toCharArray())
      {
         if (inEscape) {
            currentField.append(c);
            inEscape = false;
         }
         else if (c == ESCAPE_CHAR) {
            inEscape = true;
         } else if (c == SEPARATOR_CHAR) {
            resultList.add(currentField.toString());
            currentField.setLength(0);
         }
         else {
            currentField.append(c);
         }
      }

      if (inEscape) {
         throw new IllegalArgumentException(String.format("Unterminated escape sequence in property value: %s", value));
      }

      resultList.add(currentField.toString());
      return resultList.toArray(new String[0]);
   }

   private static Optional<Duration> parseDuration(String value)
   {
      var matcher = DURATION_PATTERN.matcher(value);
      if (matcher.matches()) {
         var number = Long.parseLong(matcher.group("number"));
         var unit = matcher.group("unit");
         switch (unit) {
            case "ms":
               return Optional.of(Duration.ofMillis(number));
            case "s":
               return Optional.of(Duration.ofSeconds(number));
            case "m":

View on GitHub (pinned to a4d93f4f85)

Solutions

  1. Terminate or remove the trailing escape character in the offending property value
  2. Escape backslashes properly (use \\\\ for a literal backslash where the format expects doubling)
  3. For filesystem paths prefer forward slashes or pass them via dataSourceProperties map in code rather than flat properties
  4. Validate property values before feeding them to HikariConfig(Properties)

Example fix

# before
dataSourceProperties.serverName=myhost\\

# after
dataSourceProperties.serverName=myhost
Defensive patterns

Strategy: validation

Validate before calling

static boolean hasUnterminatedEscape(String v) {
    boolean esc = false;
    for (char c : v.toCharArray()) {
        esc = (esc && c != PropertyElf.ESCAPE_CHAR) ? false : (c == PropertyElf.ESCAPE_CHAR && !esc);
        // simplified parity check
    }
    return false;
}
// simpler: reject values ending in a single backslash
boolean bad = value.endsWith("\\") && !value.endsWith("\\\\");

Try / catch

try { new HikariConfig(props); }
catch (IllegalArgumentException e) {
    if (e.getMessage().contains("Unterminated escape sequence")) { /* fix trailing backslash in value */ }
    throw e;
}

Prevention

When it happens

Trigger: A properties value ending with a lone backslash before the closing state, e.g. dataSourceProperties with a Windows path or regex ending in \\; doubling of a separator escaped at value end; hand-edited property files with trailing escape characters.

Common situations: Windows file paths in dataSourceProperties values, regex or glob patterns as property values, escaping mistakes when programmatically building property strings.

Related errors


AI-assisted analysis of brettwooldridge/HikariCP@a4d93f4f85 (2026-08-14). Data as JSON: /api/errors/01c7fc45ea0bf0b5. Report an issue: GitHub.