From 009aa1067cd096871e6e33e4a90e9a6f66d5718b Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Fri, 2 Aug 2024 09:04:51 -0700 Subject: [PATCH] Reduce the use of reflection in some rare circumstances (#290) --- .../service/EnvInjectMasterEnvVarsSetter.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectMasterEnvVarsSetter.java b/src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectMasterEnvVarsSetter.java index 6e883640..0d53408c 100644 --- a/src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectMasterEnvVarsSetter.java +++ b/src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectMasterEnvVarsSetter.java @@ -43,6 +43,18 @@ private Field getModifiers() throws NoSuchMethodException, InvocationTargetExcep @Override public Void call() throws EnvInjectException { + if (EnvVars.masterEnvVars.equals(enVars)) { + // Nothing to update + return null; + } else if (EnvVars.masterEnvVars.keySet().equals(enVars.keySet())) { + /* + * Per the Javadoc, merely changing the value associated with an existing key is not a structural + * modification and thus does not require synchronization. + */ + EnvVars.masterEnvVars.putAll(enVars); + return null; + } + try { Field platformField = EnvVars.class.getDeclaredField("platform"); platformField.setAccessible(true);