diff --git a/spring-core/src/main/java/org/springframework/core/env/JOptCommandLinePropertySource.java b/spring-core/src/main/java/org/springframework/core/env/JOptCommandLinePropertySource.java index 22353e0989..2eb456b176 100644 --- a/spring-core/src/main/java/org/springframework/core/env/JOptCommandLinePropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/JOptCommandLinePropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,11 @@ import org.springframework.util.StringUtils; * // ... * } * - * See {@link CommandLinePropertySource} for complete general usage examples. + *

If an option has several representations, the most descriptive is expected + * to be set last, and is used as the property name of the associated + * {@link EnumerablePropertySource#getPropertyNames()}. + * + *

See {@link CommandLinePropertySource} for complete general usage examples. * *

Requires JOpt Simple version 4.3 or higher. Tested against JOpt up until 5.0. * @@ -88,9 +92,9 @@ public class JOptCommandLinePropertySource extends CommandLinePropertySource names = new ArrayList<>(); for (OptionSpec spec : this.source.specs()) { + // Last option is expected to be the most descriptive. String lastOption = CollectionUtils.lastElement(spec.options()); if (lastOption != null) { - // Only the longest name is used for enumerating names.add(lastOption); } }