From 98ac2b04a469af0b0d69d17ef66799fb46a9c4ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20de=20Talhou=C3=ABt?= Date: Fri, 29 Apr 2016 07:54:00 -0400 Subject: [PATCH] Bug 5819 - Violation of synchronization rules in AbstractSchemaRepository MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Robert Varga (cherry picked from commit 36bdb3a032d4924b36dc86d782e58043954adadc) --- .../model/repo/util/AbstractSchemaRepository.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaRepository.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaRepository.java index bb6d1d4eb8..2413c6fc96 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaRepository.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaRepository.java @@ -87,13 +87,18 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche @Override public CheckedFuture getSchemaSource(final SourceIdentifier id, final Class representation) { - final ListMultimap, AbstractSchemaSourceRegistration> srcs = sources.get(id); - if (srcs == null) { - return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException("No providers registered for source" + id, id)); + final ArrayList> sortedSchemaSourceRegistrations; + + synchronized (this) { + final ListMultimap, AbstractSchemaSourceRegistration> srcs = sources.get(id); + if (srcs == null) { + return Futures.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) - final ArrayList> sortedSchemaSourceRegistrations = Lists.newArrayList(srcs.get(representation)); Collections.sort(sortedSchemaSourceRegistrations, SchemaProviderCostComparator.INSTANCE); final Iterator> regs = sortedSchemaSourceRegistrations.iterator(); -- 2.36.6