apache / shardingsphere-elasticjob

Distributed scheduled job
Apache License 2.0
8.15k stars 3.29k forks source link

getShardingInfo Report NullPointerException #2452

Open ExploreHeart opened 1 month ago

ExploreHeart commented 1 month ago

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details. If no response anymore and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ElasticJob did you use?

elasticjob 3.0.4

Expected behavior

Actual behavior

java.lang.NullPointerException: null
    at java.io.StringReader.<init>(StringReader.java:50)
    at org.yaml.snakeyaml.reader.StreamReader.<init>(StreamReader.java:57)
    at org.yaml.snakeyaml.Yaml.loadAs(Yaml.java:473)
    at org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine.unmarshal(YamlEngine.java:54)
    at org.apache.shardingsphere.elasticjob.lite.lifecycle.internal.statistics.ShardingStatisticsAPIImpl.getShardingInfo(ShardingStatisticsAPIImpl.java:64)
    at org.apache.shardingsphere.elasticjob.lite.lifecycle.internal.statistics.ShardingStatisticsAPIImpl.getShardingInfo(ShardingStatisticsAPIImpl.java:47)

Reason analyze (If you can)

private ShardingInfo getShardingInfo(final String jobName, final String item) {
       //Obtain the instance. However, the instance may be an offline instance.
        String instanceId = regCenter.get(jobNodePath.getShardingNodePath(item, "instance"));
        if (null != instanceId) {
            // The online instance data is obtained from the instance node based on the offline instance. In this case, the returned result is null.
            JobInstance jobInstance = YamlEngine.unmarshal(regCenter.get(jobNodePath.getInstanceNodePath(instanceId)), JobInstance.class);
            result.setServerIp(jobInstance.getServerIp());
            result.setInstanceId(jobInstance.getJobInstanceId());
        }
    }

Steps to reproduce the behavior.

Example codes for reproduce this issue (such as a github link).

linghengqian commented 1 month ago

Do you plan to submit PR?