Skip to content

NPE when update Gateway Flow Rule before the api has been requested once #1724

@dani3lWong

Description

@dani3lWong

Issue Description

Type: bug report

Describe what happened (or what feature you want)

When my program update the rule whith :
GatewayRuleManager.loadRules(new HashSet<>(FLOW_RULES.values()));

if there has one or more Api has not been requested ,
then there the api resource has not related metric.
that will throws a NPE:

java.lang.NullPointerException: null
	at com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager$GatewayRulePropertyListener.applyToConvertedParamMap(GatewayRuleManager.java:230) ~[sentinel-api-gateway-adapter-common-1.8.0.jar:na]
	at com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager$GatewayRulePropertyListener.applyGatewayRuleInternal(GatewayRuleManager.java:200) ~[sentinel-api-gateway-adapter-common-1.8.0.jar:na]
	at com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager$GatewayRulePropertyListener.configUpdate(GatewayRuleManager.java:118) ~[sentinel-api-gateway-adapter-common-1.8.0.jar:na]
	at com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager$GatewayRulePropertyListener.configUpdate(GatewayRuleManager.java:114) ~[sentinel-api-gateway-adapter-common-1.8.0.jar:na]
	at com.alibaba.csp.sentinel.property.DynamicSentinelProperty.updateValue(DynamicSentinelProperty.java:57) ~[sentinel-core-1.8.0.jar:1.8.0]
	at com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager.loadRules(GatewayRuleManager.java:78) ~[sentinel-api-gateway-adapter-common-1.8.0.jar:na]
	at ****.java:50) ~[classes/:na]
	at ****.java:102) ~[classes/:na]
	at ****.java:52) ~[classes/:na]
	at sun.reflect.GeneratedMethodAccessor81.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_201]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_201]
	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) [spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_201]
	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_201]
	at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_201]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_201]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_201]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_201]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_201]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_201]

Because there has not metric for this resource , but the method:

com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager.GatewayRulePropertyListener private void applyToConvertedParamMap(@NotNull Set<ParamFlowRule> paramFlowRules)

try to clear that with :

ParameterMetricStorage.getParamMetricForResource(resource).clearForRule(rule);

in com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager.GatewayRulePropertyListener
(233 line in com/alibaba/csp/sentinel/adapter/gateway/common/rule/GatewayRuleManager.java)

Describe what you expected to happen

How to reproduce it (as minimally and precisely as possible)

  1. init a api resource with gateway rule manager
  2. update that before that has been requested

Tell us your environment

Sentinel Version : 1.8

Anything else we need to know?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/gateway-flow-controlIssues or PRs related to API gateway flow controlgood first issueGood for newcomerskind/bugCategory issues or prs related to bug.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions