This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch 
4281-enenvironmentvariable-getvalueorresolve-is-broken
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to 
refs/heads/4281-enenvironmentvariable-getvalueorresolve-is-broken by this push:
     new c556600eab fix(#4281): honor env values in getValueOrResolve
c556600eab is described below

commit c556600eab7cd0a97a4c6a8c259a891edb1a704b
Author: Philipp Zehnder <[email protected]>
AuthorDate: Mon Mar 23 11:57:39 2026 +0100

    fix(#4281): honor env values in getValueOrResolve
---
 .../environment/variable/EnvironmentVariable.java  |  2 +-
 .../variable/EnvironmentVariableTest.java          | 73 ++++++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)

diff --git 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/variable/EnvironmentVariable.java
 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/variable/EnvironmentVariable.java
index 4219c51d30..462899bbe5 100644
--- 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/variable/EnvironmentVariable.java
+++ 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/variable/EnvironmentVariable.java
@@ -50,7 +50,7 @@ public abstract class EnvironmentVariable<T> {
   }
 
   public T getValueOrResolve(EnvResolver<T> resolver) {
-    return resolver.resolve();
+    return exists() ? getValue() : resolver.resolve();
   }
 
   public T getDefault() {
diff --git 
a/streampipes-commons/src/test/java/org/apache/streampipes/commons/environment/variable/EnvironmentVariableTest.java
 
b/streampipes-commons/src/test/java/org/apache/streampipes/commons/environment/variable/EnvironmentVariableTest.java
new file mode 100644
index 0000000000..9c6bf8fb31
--- /dev/null
+++ 
b/streampipes-commons/src/test/java/org/apache/streampipes/commons/environment/variable/EnvironmentVariableTest.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.commons.environment.variable;
+
+import org.apache.streampipes.commons.constants.Envs;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class EnvironmentVariableTest {
+
+  @Test
+  void getValueOrResolveUsesExistingValue() {
+    var variable = new TestEnvironmentVariable(true, "configured-value");
+
+    var result = variable.getValueOrResolve(() -> "resolved-value");
+
+    assertEquals("configured-value", result);
+  }
+
+  @Test
+  void getValueOrResolveUsesResolverWhenValueMissing() {
+    var variable = new TestEnvironmentVariable(false, "configured-value");
+
+    var result = variable.getValueOrResolve(() -> "resolved-value");
+
+    assertEquals("resolved-value", result);
+  }
+
+  private static final class TestEnvironmentVariable extends 
EnvironmentVariable<String> {
+
+    private final boolean exists;
+    private final String value;
+
+    private TestEnvironmentVariable(boolean exists, String value) {
+      super(Envs.SP_NATS_HOST);
+      this.exists = exists;
+      this.value = value;
+    }
+
+    @Override
+    public String getValue() {
+      return value;
+    }
+
+    @Override
+    public boolean exists() {
+      return exists;
+    }
+
+    @Override
+    public String parse(String value) {
+      return value;
+    }
+  }
+}

Reply via email to