From d5d14ecdcd1280b1b82ae1ae6be00f2a64e9b510 Mon Sep 17 00:00:00 2001 From: Craig Bryant Date: Thu, 9 Jun 2016 14:35:01 -0600 Subject: [PATCH] Clone the currentValues property in duplicate method It is possible for the currentValues property to change which can cause java.util.ConcurrentModificationException. Fix by cloning currentValues before the SubAlarm gets emitted into storm Change-Id: I555beffafe0208c0d256732517af401938876d3d --- .../thresholding/MetricAggregationBolt.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/thresh/src/main/java/monasca/thresh/infrastructure/thresholding/MetricAggregationBolt.java b/thresh/src/main/java/monasca/thresh/infrastructure/thresholding/MetricAggregationBolt.java index d5b6a7d..5bec0e0 100644 --- a/thresh/src/main/java/monasca/thresh/infrastructure/thresholding/MetricAggregationBolt.java +++ b/thresh/src/main/java/monasca/thresh/infrastructure/thresholding/MetricAggregationBolt.java @@ -1,5 +1,5 @@ /* - * (C) Copyright 2014,2016 Hewlett Packard Enterprise Development Company LP. + * (C) Copyright 2014-2016 Hewlett Packard Enterprise Development Company LP. * Copyright 2016 FUJITSU LIMITED * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -41,9 +41,11 @@ import org.apache.storm.tuple.Values; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -235,10 +237,24 @@ public class MetricAggregationBolt extends BaseRichBolt { new SubAlarm(original.getId(), original.getAlarmId(), new SubExpression( original.getAlarmSubExpressionId(), original.getExpression()), original.getState()); newSubAlarm.setNoState(original.isNoState()); - newSubAlarm.setCurrentValues(original.getCurrentValues()); + newSubAlarm.setCurrentValues(cloneCurrentValues(original)); return newSubAlarm; } + /** + * Shallow clone of the List. Doubles are immutable so no point in doing a deep copy + * + * @param original List + * @return null if original is null, other shallow clone of original + */ + private List cloneCurrentValues(final SubAlarm original) { + final List originalCurrentValues = original.getCurrentValues(); + if (originalCurrentValues == null) { + return null; + } + return new ArrayList(originalCurrentValues); + } + /** * Only used for testing. *