Skip to content

Commit b727406

Browse files
pure: Store variable values in a ThreadLocal map
To ensure that variable values are not overwritten when different XML are validated on separate threads, store the variable values in aborts ThreadLocal map. Fixes issue #182.
1 parent a2b30c0 commit b727406

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

ph-schematron-pure/src/main/java/com/helger/schematron/pure/xpath/XPathLetVariableResolver.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@
3030
@NotThreadSafe
3131
public class XPathLetVariableResolver implements XPathVariableResolver
3232
{
33-
private final ICommonsMap <QName, Object> m_aVariables = new CommonsHashMap <> ();
33+
private final ThreadLocal<ICommonsMap <QName, Object>> m_aVariables = new ThreadLocal<> () {
34+
@Override
35+
protected ICommonsMap <QName, Object> initialValue()
36+
{
37+
return new CommonsHashMap <> ();
38+
}
39+
};
40+
3441
private final XPathVariableResolver m_aDelegatedResolver;
3542

3643
public XPathLetVariableResolver (@Nullable final XPathVariableResolver aResolver)
@@ -41,7 +48,7 @@ public XPathLetVariableResolver (@Nullable final XPathVariableResolver aResolver
4148
public void setVariableValue (@Nonnull final QName aVariableName, @Nullable final Object aValue)
4249
{
4350
ValueEnforcer.notNull (aVariableName, "VariableName");
44-
m_aVariables.put (aVariableName, aValue);
51+
m_aVariables.get().put (aVariableName, aValue);
4552
}
4653

4754
/**
@@ -53,7 +60,7 @@ public void setVariableValue (@Nonnull final QName aVariableName, @Nullable fina
5360
public void removeVariable (@Nullable final QName aVariableName)
5461
{
5562
if (aVariableName != null)
56-
m_aVariables.remove (aVariableName);
63+
m_aVariables.get().remove (aVariableName);
5764
}
5865

5966
@Override
@@ -62,7 +69,7 @@ public Object resolveVariable (@Nullable final QName aVariableName)
6269
if (aVariableName != null)
6370
{
6471
// 1. variables
65-
final Object result = m_aVariables.get (aVariableName);
72+
final Object result = m_aVariables.get().get (aVariableName);
6673
if (result != null)
6774
return result;
6875

0 commit comments

Comments
 (0)