As noted by @GuardedBy annotation, access to sources field need to be
performed while holding the object monitor. Refactor getSchemaSource()
to create a copy under lock and then release it for further processing.
Change-Id: I65fddf5830e657c3601c85fd976f12e3c8bb3ff6
Signed-off-by: Alexis de Talhouët <adetalhouet@inocybe.com>
Signed-off-by: Robert Varga <nite@hq.sk>
(cherry picked from commit
36bdb3a032d4924b36dc86d782e58043954adadc)
@Override
public <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> getSchemaSource(final SourceIdentifier id, final Class<T> representation) {
@Override
public <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> getSchemaSource(final SourceIdentifier id, final Class<T> representation) {
- final ListMultimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> srcs = sources.get(id);
- if (srcs == null) {
- return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(new MissingSchemaSourceException("No providers registered for source" + id, id));
+ final ArrayList<AbstractSchemaSourceRegistration<?>> sortedSchemaSourceRegistrations;
+
+ synchronized (this) {
+ final ListMultimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> srcs = sources.get(id);
+ if (srcs == null) {
+ return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(new MissingSchemaSourceException("No providers registered for source" + id, id));
+ }
+
+ sortedSchemaSourceRegistrations = Lists.newArrayList(srcs.get(representation));
}
// TODO, remove and make sources keep sorted multimap (e.g. ArrayListMultimap with SortedLists)
}
// TODO, remove and make sources keep sorted multimap (e.g. ArrayListMultimap with SortedLists)
- final ArrayList<AbstractSchemaSourceRegistration<?>> sortedSchemaSourceRegistrations = Lists.newArrayList(srcs.get(representation));
Collections.sort(sortedSchemaSourceRegistrations, SchemaProviderCostComparator.INSTANCE);
final Iterator<AbstractSchemaSourceRegistration<?>> regs = sortedSchemaSourceRegistrations.iterator();
Collections.sort(sortedSchemaSourceRegistrations, SchemaProviderCostComparator.INSTANCE);
final Iterator<AbstractSchemaSourceRegistration<?>> regs = sortedSchemaSourceRegistrations.iterator();