Skip to content

Commit e5ead3a

Browse files
committed
[bugfix] util:system-property should be deterministic within the execution scope
1 parent b1f1abd commit e5ead3a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

exist-core/src/main/java/org/exist/xquery/XQueryContext.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ public class XQueryContext implements BinaryValueManager, Context {
376376
//For holding the environment variables
377377
private IMap<String, String> envs;
378378

379+
//For holding the Java System Properties
380+
private IMap<String, String> props;
381+
379382
private ContextUpdateListener updateListener = null;
380383

381384
private boolean enableOptimizer = true;
@@ -2741,6 +2744,26 @@ public io.lacuna.bifurcan.IMap<String, String> getEnvironmentVariables() {
27412744
return envs;
27422745
}
27432746

2747+
/**
2748+
* Get Java System properties. The properties shall not change
2749+
* during execution of query.
2750+
*
2751+
* @return Map of Java System Properties
2752+
*/
2753+
public io.lacuna.bifurcan.IMap<String, String> getJavaSystemProperties() {
2754+
if (props == null) {
2755+
final IMap<String, String> strProps = new LinearMap<>();
2756+
for (final Map.Entry<Object, Object> prop : System.getProperties().entrySet()) {
2757+
final Object value = prop.getValue();
2758+
if (value instanceof String) {
2759+
strProps.put(prop.getKey().toString(), (String) value);
2760+
}
2761+
}
2762+
props = strProps.forked();
2763+
}
2764+
return props;
2765+
}
2766+
27442767
/**
27452768
* Gets the Effective user
27462769
* i.e. the user that the query is executing as

exist-core/src/main/java/org/exist/xquery/functions/util/SystemProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
6060
final String key = args[0].getStringValue();
6161
String value = ExistSystemProperties.getInstance().getExistSystemProperty(key, null);
6262
if (value == null) {
63-
value = System.getProperty(key);
63+
value = context.getJavaSystemProperties().get(key, null);
6464
}
6565
return value == null ? Sequence.EMPTY_SEQUENCE : new StringValue(this, value);
6666
}

0 commit comments

Comments
 (0)