Skip to content

fix: min idle connection envvar 9.1#306

Merged
tamassoltesz merged 3 commits into
9.1from
fix/min_idle_connection_envvar_9_1
Mar 18, 2026
Merged

fix: min idle connection envvar 9.1#306
tamassoltesz merged 3 commits into
9.1from
fix/min_idle_connection_envvar_9_1

Conversation

@tamassoltesz

Copy link
Copy Markdown
Collaborator

Summary of change

(A few sentences about this PR)

Related issues

  • Link to issue1 here
  • Link to issue1 here

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your
changes work. Bonus points for screenshots and videos!)

Documentation changes

(If relevant, please create a PR in our docs repo, or create a checklist here
highlighting the necessary changes)

Checklist for important updates

  • Changelog has been updated
  • pluginInterfaceSupported.json file has been updated (if needed)
  • Changes to the version if needed
    • In build.gradle
  • Had installed and ran the pre-commit hook
  • If there are new dependencies that have been added in build.gradle, please make sure to add them
    in implementationDependencies.json.
  • Issue this PR against the latest non released version branch.
    • To know which one it is, run find the latest released tag (git tag) in the format vX.Y.Z, and then find the
      latest branch (git branch --all) whose X.Y is greater than the latest released tag.
    • If no such branch exists, then create one from the latest released branch.
  • When adding new recipes, ensure that its performance is being measured in the OneMillionUsersTest

Remaining TODOs for this PR

  • Item1
  • Item2

Comment on lines +30 to +56
private static void setEnv(String key, String value) {
try {
Map<String, String> env = System.getenv();
Class<?> cl = env.getClass();
Field field = cl.getDeclaredField("m");
field.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, String> writableEnv = (Map<String, String>) field.get(env);
writableEnv.put(key, value);
} catch (Exception e) {
throw new IllegalStateException("Failed to set environment variable", e);
}
}

private static void removeEnv(String key) {
try {
Map<String, String> env = System.getenv();
Class<?> cl = env.getClass();
Field field = cl.getDeclaredField("m");
field.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, String> writableEnv = (Map<String, String>) field.get(env);
writableEnv.remove(key);
} catch (Exception e) {
throw new IllegalStateException("Failed to remove environment variable", e);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The setEnv() and removeEnv() methods rely on accessing an internal field named "m" from the System.getenv() map class. This field name is JVM implementation-specific and may not exist in all JVM implementations (e.g., different vendors, GraalVM native image, etc.), causing the tests to fail with NoSuchFieldException.

// Current code assumes field "m" exists
Field field = cl.getDeclaredField("m");

This will break the test suite on non-standard JVMs. Consider using a more robust approach like JUnit's @SetEnvironmentVariable from system-lambda library, or document that these tests only work on specific JVM implementations.

Suggested change
private static void setEnv(String key, String value) {
try {
Map<String, String> env = System.getenv();
Class<?> cl = env.getClass();
Field field = cl.getDeclaredField("m");
field.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, String> writableEnv = (Map<String, String>) field.get(env);
writableEnv.put(key, value);
} catch (Exception e) {
throw new IllegalStateException("Failed to set environment variable", e);
}
}
private static void removeEnv(String key) {
try {
Map<String, String> env = System.getenv();
Class<?> cl = env.getClass();
Field field = cl.getDeclaredField("m");
field.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, String> writableEnv = (Map<String, String>) field.get(env);
writableEnv.remove(key);
} catch (Exception e) {
throw new IllegalStateException("Failed to remove environment variable", e);
}
}
private static void setEnv(String key, String value) {
try {
Map<String, String> env = System.getenv();
Class<?> cl = env.getClass();
Field field = null;
// Try common field names used by different JVM implementations
String[] possibleFieldNames = {"m", "theUnmodifiableEnvironment", "theEnvironment"};
for (String fieldName : possibleFieldNames) {
try {
field = cl.getDeclaredField(fieldName);
break;
} catch (NoSuchFieldException e) {
// Continue to next field name
}
}
if (field == null) {
throw new IllegalStateException("Unable to find environment map field in " + cl.getName() +
". This test may not work on this JVM implementation.");
}
field.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, String> writableEnv = (Map<String, String>) field.get(env);
writableEnv.put(key, value);
} catch (Exception e) {
throw new IllegalStateException("Failed to set environment variable. Consider using system-lambda or similar library for better JVM compatibility.", e);
}
}
private static void removeEnv(String key) {
try {
Map<String, String> env = System.getenv();
Class<?> cl = env.getClass();
Field field = null;
// Try common field names used by different JVM implementations
String[] possibleFieldNames = {"m", "theUnmodifiableEnvironment", "theEnvironment"};
for (String fieldName : possibleFieldNames) {
try {
field = cl.getDeclaredField(fieldName);
break;
} catch (NoSuchFieldException e) {
// Continue to next field name
}
}
if (field == null) {
throw new IllegalStateException("Unable to find environment map field in " + cl.getName() +
". This test may not work on this JVM implementation.");
}
field.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, String> writableEnv = (Map<String, String>) field.get(env);
writableEnv.remove(key);
} catch (Exception e) {
throw new IllegalStateException("Failed to remove environment variable. Consider using system-lambda or similar library for better JVM compatibility.", e);
}
}

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@tamassoltesz tamassoltesz merged commit be127bc into 9.1 Mar 18, 2026
3 of 4 checks passed
@tamassoltesz tamassoltesz deleted the fix/min_idle_connection_envvar_9_1 branch March 18, 2026 11:46
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