Skip to content

Commit

Permalink
Fix potential NPE bug when updating ParamFlowRule before the resource…
Browse files Browse the repository at this point in the history
… has been requested once (#1901)
  • Loading branch information
brotherlu-xcq authored Dec 18, 2020
1 parent 82826fa commit 70b457b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ private Map<String, List<ParamFlowRule>> aggregateAndPrepareParamRules(List<Para
List<ParamFlowRule> oldRuleList = new ArrayList<>(entry.getValue());
oldRuleList.removeAll(newRuleList);
for (ParamFlowRule rule : oldRuleList) {
ParameterMetricStorage.getParamMetricForResource(resource).clearForRule(rule);
ParameterMetric parameterMetric = ParameterMetricStorage.getParamMetricForResource(resource);
if (parameterMetric != null) {
parameterMetric.clearForRule(rule);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,18 @@ public void testLoadParamRulesAndGet() {
assertTrue(allRules.contains(ruleC));
assertTrue(allRules.contains(ruleD));
}

@Test
public void testLoadParamRulesWithNoMetric() {
String resource = "test";
ParamFlowRule paramFlowRule = new ParamFlowRule(resource)
.setDurationInSec(1).setParamIdx(1);
ParamFlowRuleManager.loadRules(Collections.singletonList(paramFlowRule));
ParamFlowRule newParamFlowRule = new ParamFlowRule(resource)
.setDurationInSec(2).setParamIdx(1);
ParamFlowRuleManager.loadRules(Collections.singletonList(newParamFlowRule));
List<ParamFlowRule> result = ParamFlowRuleManager.getRulesOfResource(resource);
assertEquals(1, result.size());
assertEquals(2, result.get(0).getDurationInSec());
}
}

0 comments on commit 70b457b

Please sign in to comment.