Skip to content

Commit cf21f69

Browse files
Add error handling for missing secrets in configuration
1 parent c58a92b commit cf21f69

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

ojdbc-provider-common/src/main/java/oracle/jdbc/provider/util/ParameterUtil.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,25 @@ public static String getEnvOrProperty(String key) {
2525
}
2626

2727
/**
28-
* Fetches a parameter from the ParameterSet or falls back to environment/system properties.
28+
* Fetches a parameter from the ParameterSet or falls back to
29+
* environment/system properties.
2930
*
3031
* @param parameterSet the ParameterSet to search for the parameter
3132
* @param parameter the Parameter to fetch from the ParameterSet
3233
* @param envKey the environment/system property key to use as fallback
33-
* @return the parameter value, or the environment/system property value if the parameter is not set
34+
* @return the parameter value
35+
* @throws IllegalStateException if neither the parameter nor
36+
* the environment/system property is found
3437
*/
35-
public static String getRequiredOrFallback(ParameterSet parameterSet, Parameter<String> parameter, String envKey) {
36-
return Optional.ofNullable(parameterSet.getOptional(parameter))
37-
.orElse(getEnvOrProperty(envKey));
38+
public static String getRequiredOrFallback(
39+
ParameterSet parameterSet, Parameter<String> parameter, String envKey) {
40+
String value = Optional.ofNullable(parameterSet.getOptional(parameter))
41+
.orElse(getEnvOrProperty(envKey));
42+
43+
if (value == null || value.isEmpty()) {
44+
throw new IllegalStateException(
45+
"Required configuration '" + envKey + "' not found in ParameterSet, system properties, or environment variables.");
46+
}
47+
return value;
3848
}
3949
}

0 commit comments

Comments
 (0)