Skip to content

Commit

Permalink
[GR-43126] Ensure setting same system property multiple times via com…
Browse files Browse the repository at this point in the history
…mand line is allowed.

PullRequest: graal/13417
  • Loading branch information
olpaw committed Dec 19, 2022
2 parents 24c36c8 + 9267a04 commit d068d43
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

import java.util.Arrays;

import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.MapCursor;

import com.oracle.svm.core.jdk.SystemPropertiesSupport;

public final class RuntimePropertyParser {
Expand All @@ -40,16 +43,21 @@ public final class RuntimePropertyParser {
*/
public static String[] parse(String[] args) {
int newIdx = 0;
EconomicMap<String, String> properties = EconomicMap.create();
for (int oldIdx = 0; oldIdx < args.length; oldIdx++) {
String arg = args[oldIdx];
if (arg.startsWith(PROPERTY_PREFIX) && parseProperty(arg.substring(PROPERTY_PREFIX.length()))) {
if (arg.startsWith(PROPERTY_PREFIX) && parseProperty(arg.substring(PROPERTY_PREFIX.length()), properties)) {
// Option consumed
} else {
assert newIdx <= oldIdx;
args[newIdx] = arg;
newIdx++;
}
}
MapCursor<String, String> cursor = properties.getEntries();
while (cursor.advance()) {
SystemPropertiesSupport.singleton().initializeProperty(cursor.getKey(), cursor.getValue());
}
if (newIdx == args.length) {
/* We can be allocation free and just return the original arguments. */
return args;
Expand All @@ -58,7 +66,7 @@ public static String[] parse(String[] args) {
}
}

private static boolean parseProperty(String property) {
private static boolean parseProperty(String property, EconomicMap<String, String> parsedProperties) {
int splitIndex = property.indexOf('=');
if (splitIndex == -1) {
return false;
Expand All @@ -67,7 +75,7 @@ private static boolean parseProperty(String property) {
String key = property.substring(0, splitIndex);
String value = property.substring(splitIndex + 1);

SystemPropertiesSupport.singleton().initializeProperty(key, value);
parsedProperties.put(key, value);

return true;
}
Expand Down

0 comments on commit d068d43

Please sign in to comment.