Skip to content

Commit bedb8c2

Browse files
committed
Introduce constants for repeated strings
1 parent fc4652c commit bedb8c2

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

internal-api/src/main/java/datadog/trace/bootstrap/config/provider/StableConfigParser.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
public class StableConfigParser {
2020
private static final Logger log = LoggerFactory.getLogger(StableConfigParser.class);
2121

22+
private static final String ENVIRONMENT_VARIABLES_PREFIX = "environment_variables['";
23+
private static final String PROCESS_ARGUMENTS_PREFIX = "process_arguments['";
24+
private static final String UNDEFINED_VALUE = "UNDEFINED";
25+
2226
/**
2327
* Parses a configuration file and returns a stable configuration object.
2428
*
@@ -230,37 +234,39 @@ static String processTemplate(String content) throws IOException {
230234
}
231235

232236
private static String processTemplateVar(String templateVar) throws IOException {
233-
if (templateVar.startsWith("environment_variables['") && templateVar.endsWith("']")) {
237+
if (templateVar.startsWith(ENVIRONMENT_VARIABLES_PREFIX) && templateVar.endsWith("']")) {
234238
String envVar =
235239
templateVar
236-
.substring("environment_variables['".length(), templateVar.length() - 2)
240+
.substring(ENVIRONMENT_VARIABLES_PREFIX.length(), templateVar.length() - 2)
237241
.trim();
238242
if (envVar.isEmpty()) {
239243
throw new IOException("Empty environment variable name in template");
240244
}
241245
String value = System.getenv(envVar.toUpperCase());
242246
if (value == null || value.isEmpty()) {
243-
return "UNDEFINED";
247+
return UNDEFINED_VALUE;
244248
}
245249
return value;
246-
} else if (templateVar.startsWith("process_arguments['") && templateVar.endsWith("']")) {
250+
} else if (templateVar.startsWith(PROCESS_ARGUMENTS_PREFIX) && templateVar.endsWith("']")) {
247251
String processArg =
248-
templateVar.substring("process_arguments['".length(), templateVar.length() - 2).trim();
252+
templateVar.substring(PROCESS_ARGUMENTS_PREFIX.length(), templateVar.length() - 2).trim();
249253
if (processArg.isEmpty()) {
250254
throw new IOException("Empty process argument in template");
251255
}
252256
if (!processArg.startsWith("-D")) {
253257
log.warn(
254-
"Ignoring unsupported process_arguments entry in template variable, '{}'. Only system properties specified with the '-D' prefix are supported.",
258+
"Ignoring unsupported process_arguments entry in template variable, '{}'."
259+
+ " Only system properties specified with the '-D' prefix are supported.",
255260
processArg);
256-
return "UNDEFINED";
261+
return UNDEFINED_VALUE;
257262
}
258263
String value = System.getProperty(processArg.substring(2));
259264
if (value == null || value.isEmpty()) {
260-
return "UNDEFINED";
265+
return UNDEFINED_VALUE;
261266
}
262267
return value;
268+
} else {
269+
return UNDEFINED_VALUE;
263270
}
264-
return "UNDEFINED";
265271
}
266272
}

0 commit comments

Comments
 (0)