From b25e6b15e9cfc1d6752e5a4ffb91a76728c7e478 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Tue, 5 Feb 2019 22:00:55 -0500 Subject: [PATCH] Guards against NPE. see gh-789 --- .../gateway/filter/WeightCalculatorWebFilter.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java index 72f8d567..a84cc862 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java @@ -184,7 +184,16 @@ public class WeightCalculatorWebFilter implements WebFilter, Ordered, SmartAppli public Mono filter(ServerWebExchange exchange, WebFilterChain chain) { Map weights = getWeights(exchange); - groupWeights.forEach((group, config) -> { + for (String group : groupWeights.keySet()) { + GroupWeightConfig config = groupWeights.get(group); + + if (config == null) { + if (log.isDebugEnabled()) { + log.debug("No GroupWeightConfig found for group: " + group); + } + continue; // nothing we can do, but this is odd + } + double r = this.random.nextDouble(); List ranges = config.ranges; @@ -200,7 +209,7 @@ public class WeightCalculatorWebFilter implements WebFilter, Ordered, SmartAppli break; } } - }); + } if (log.isTraceEnabled()) { log.trace("Weights attr: "+weights);