From 07b989f00e1bf45643f1b2ecc40369087430e36b Mon Sep 17 00:00:00 2001 From: serso Date: Wed, 26 Jul 2017 10:16:59 +0200 Subject: [PATCH] Fix IndexOutOfBoundsException caused by asynchronous init of MathRegistry --- .../org/solovyev/common/math/AbstractMathRegistry.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jscl/src/main/java/org/solovyev/common/math/AbstractMathRegistry.java b/jscl/src/main/java/org/solovyev/common/math/AbstractMathRegistry.java index 97797e9c..862a571b 100644 --- a/jscl/src/main/java/org/solovyev/common/math/AbstractMathRegistry.java +++ b/jscl/src/main/java/org/solovyev/common/math/AbstractMathRegistry.java @@ -170,7 +170,9 @@ public abstract class AbstractMathRegistry implements Math public List getNames() { synchronized (this) { if (!entityNames.isEmpty()) { - return entityNames; + // if the registry is not initialized yet we expect entityNames to be updated on a + // background thread => return its copy + return !initialized ? new ArrayList<>(entityNames) : entityNames; } for (T entity : entities) { final String name = entity.getName(); @@ -178,7 +180,9 @@ public abstract class AbstractMathRegistry implements Math entityNames.add(name); } } - return entityNames; + // if the registry is not initialized yet we expect entityNames to be updated on a + // background thread => return its copy + return !initialized ? new ArrayList<>(entityNames) : entityNames; } }