make sure method-invocation-specified participant objects always take precedence over XML-configured ones
Project: http://git-wip-us.apache.org/repos/asf/bval/repo Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/f8da0211 Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/f8da0211 Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/f8da0211 Branch: refs/heads/bv2 Commit: f8da02117a9983615a5fc1095738f90a90c8b6b3 Parents: f783358 Author: Matt Benson <[email protected]> Authored: Fri Mar 16 17:58:52 2018 -0500 Committer: Matt Benson <[email protected]> Committed: Fri Mar 16 17:58:52 2018 -0500 ---------------------------------------------------------------------- .../org/apache/bval/jsr/ConfigurationImpl.java | 41 ++++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/bval/blob/f8da0211/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java index 3e2f678..b4d19f6 100644 --- a/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java +++ b/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java @@ -63,26 +63,35 @@ import org.apache.commons.weaver.privilizer.Privileged; public class ConfigurationImpl implements ApacheValidatorConfiguration, ConfigurationState { private class LazyParticipant<T> extends Lazy<T> { + private boolean locked; private LazyParticipant(Supplier<T> init) { super(init); } - @Override - public Lazy<T> reset(Supplier<T> init) { - try { - return super.reset(init); - } finally { - ConfigurationImpl.this.prepared = false; - } - } - ConfigurationImpl override(T value) { if (value != null) { - reset(() -> value); + synchronized (this) { + if (!locked) { + try { + reset(() -> value); + } finally { + ConfigurationImpl.this.prepared = false; + } + } + } } return ConfigurationImpl.this; } + + synchronized ConfigurationImpl externalOverride(T value) { + locked = false; + try { + return override(value); + } finally { + locked = true; + } + } } /** @@ -187,7 +196,7 @@ public class ConfigurationImpl implements ApacheValidatorConfiguration, Configur */ @Override public ConfigurationImpl messageInterpolator(MessageInterpolator resolver) { - return messageInterpolator.override(resolver); + return messageInterpolator.externalOverride(resolver); } /** @@ -195,7 +204,7 @@ public class ConfigurationImpl implements ApacheValidatorConfiguration, Configur */ @Override public ApacheValidatorConfiguration traversableResolver(TraversableResolver resolver) { - return traversableResolver.override(resolver); + return traversableResolver.externalOverride(resolver); } /** @@ -203,17 +212,17 @@ public class ConfigurationImpl implements ApacheValidatorConfiguration, Configur */ @Override public ConfigurationImpl constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory) { - return this.constraintValidatorFactory.override(constraintValidatorFactory); + return this.constraintValidatorFactory.externalOverride(constraintValidatorFactory); } @Override public ApacheValidatorConfiguration parameterNameProvider(ParameterNameProvider parameterNameProvider) { - return this.parameterNameProvider.override(parameterNameProvider); + return this.parameterNameProvider.externalOverride(parameterNameProvider); } @Override public ApacheValidatorConfiguration clockProvider(ClockProvider clockProvider) { - return this.clockProvider.override(clockProvider); + return this.clockProvider.externalOverride(clockProvider); } /** @@ -469,7 +478,7 @@ public class ConfigurationImpl implements ApacheValidatorConfiguration, Configur final String className = getClassName.get(); if (className != null) { final Class<T> t = loadClass(className); - participant.reset(() -> newInstance(t)); + participant.override(newInstance(t)); } }
