Skip to content

Fix failed-connection tests on JDK 11 and set up JDK 11 in CI - #692

Merged
sahusanket merged 2 commits into
developfrom
fix/jdk11-unit-tests
Nov 23, 2026
Merged

sahusanket merged 2 commits into
developfrom
fix/jdk11-unit-tests

Conversation

@sahusanket

Copy link
Copy Markdown
Contributor

On JDK 11, MysqlFailedConnectionTest and OracleFailedConnectionTest fail because DBSpecificFailedConnectionTest compares raw validation error strings containing Properties.toString(). Java 9+ changed Properties to store entries in an internal ConcurrentHashMap rather than Hashtable, which changes map iteration order when multiple connection properties are present. The GitHub Actions unit test workflow also runs without configuring JDK 11.

Normalize the key=value entries inside the connection arguments block in DBSpecificFailedConnectionTest before comparing messages. That keeps assertions strict on the JDBC URL, properties, and error text across JDK 8 and JDK 11. Configure Temurin 11 in the unit test workflow for branches other than release/1.11.

Verified mvn clean test -B across all 20 modules on JDK 11 passes RAT, Checkstyle, and all 207 unit tests (186 executed, 21 live-DB suites skipped).

On JDK 11, MysqlFailedConnectionTest and OracleFailedConnectionTest fail because DBSpecificFailedConnectionTest compares raw validation error strings containing Properties.toString(). Java 9+ changed Properties to store entries in an internal ConcurrentHashMap rather than Hashtable, which changes map iteration order when multiple connection properties are present. The GitHub Actions unit test workflow also runs without configuring JDK 11.

Normalize the key=value entries inside the connection arguments block in DBSpecificFailedConnectionTest before comparing messages. That keeps assertions strict on the JDBC URL, properties, and error text across JDK 8 and JDK 11. Configure Temurin 11 in the unit test workflow for branches other than release/1.11.

Verified mvn clean test -B across all 20 modules on JDK 11 passes RAT, Checkstyle, and all 207 unit tests (186 executed, 21 live-DB suites skipped).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a normalization helper, normalizeConnectionArguments, in DBSpecificFailedConnectionTest along with a new test class DBSpecificFailedConnectionMessageTest to verify its behavior. This normalization sorts connection arguments in error messages to prevent test failures caused by non-deterministic argument ordering across different JDK versions. The feedback suggests a minor optimization to simplify the sorting logic by using Arrays.sort directly on the array instead of converting it to a list, which also allows removing an unused import.

Comment on lines +72 to +74
List<String> entries = Arrays.asList(argsContent.split(", ", -1));
Collections.sort(entries);
return errorMsg.substring(0, contentStart) + String.join(", ", entries) + errorMsg.substring(argsEnd);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

We can simplify this logic by sorting the array directly using Arrays.sort instead of wrapping it in a list via Arrays.asList and calling Collections.sort. This avoids unnecessary object allocation and simplifies the code. If you apply this change, the import java.util.Collections on line 30 will also become unused and can be removed.

Suggested change
List<String> entries = Arrays.asList(argsContent.split(", ", -1));
Collections.sort(entries);
return errorMsg.substring(0, contentStart) + String.join(", ", entries) + errorMsg.substring(argsEnd);
String[] entries = argsContent.split(", ", -1);
Arrays.sort(entries);
return errorMsg.substring(0, contentStart) + String.join(", ", entries) + errorMsg.substring(argsEnd);

normalizeConnectionArguments(validationFailures.get(0).getMessage()));
}

static String normalizeConnectionArguments(String errorMsg) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can be simplified

Option 1

static String normalizeConnectionArguments(String errorMsg) {
  if (errorMsg == null) {
    return null;
  }
  int argsStart = errorMsg.indexOf(ARGS_PREFIX);
  if (argsStart < 0) {
    return errorMsg;
  }
  int contentStart = argsStart + ARGS_PREFIX.length();
  int argsEnd = errorMsg.indexOf(ARGS_SUFFIX, contentStart);
  if (argsEnd <= contentStart) { // Combines missing suffix (< 0) and empty content (== contentStart)
    return errorMsg;
  }

  String sortedArgs = Arrays.stream(errorMsg.substring(contentStart, argsEnd).split(", ", -1))
      .sorted()
      .collect(Collectors.joining(", "));

  return errorMsg.substring(0, contentStart) + sortedArgs + errorMsg.substring(argsEnd);
}

Option 2

private static final Pattern ARGS_PATTERN = Pattern.compile(
    Pattern.quote(ARGS_PREFIX) + "(.+?)" + Pattern.quote(ARGS_SUFFIX),
    Pattern.DOTALL
);

static String normalizeConnectionArguments(String errorMsg) {
  if (errorMsg == null) {
    return null;
  }
  return ARGS_PATTERN.matcher(errorMsg).replaceFirst(match -> {
    String sorted = Arrays.stream(match.group(1).split(", ", -1))
        .sorted()
        .collect(Collectors.joining(", "));
    return Matcher.quoteReplacement(ARGS_PREFIX + sorted + ARGS_SUFFIX);
  });
}

@sahusanket
sahusanket merged commit fbca6e7 into develop Nov 23, 2026
11 of 12 checks passed
@sahusanket
sahusanket deleted the fix/jdk11-unit-tests branch November 23, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants