apache / apache/shenyu

[BUG] Grpc/Dubbo/Sofa parser NPE on null labels + 4-deep service deref chain

Open
#6,861 1 comment 0 reactions 0 assignees View on GitHub
kubernetes priority: medium type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

## Description
Each parser iterates `for (String label : labels.keySet())` where `labels` comes from `ingress.getMetadata().getLabels()`, which returns null when no labels are set — `labels.keySet()` NPEs. Inside the loop, `serviceLister.namespace(namespace).get(labels.get(label)).getMetadata().getAnnotations()` is a 4-deep deref chain with no null check — if the referenced Service does not exist, `.getMetadata()` NPEs.

## Location
- `shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/parser/GrpcParser.java:255-256`
- `shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/parser/DubboIngressParser.java:241-242`
- `shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/parser/SofaParser.java:172-173`

## Impact
A gRPC/Dubbo/Sofa ingress with no k8s labels (or referencing a non-existent Service) crashes the reconcile with NPE, blocking route configuration for that ingress.

## Suggested fix
Null-check `labels` before the loop (`if (Objects.isNull(labels)) return res;`); inside the loop, fetch `V1Service svc = serviceLister.namespace(namespace).get(labels.get(label)); if (Objects.isNull(svc)) { continue; }` before dereferencing.

## Related existing
None — the label-chain deref pattern is not covered by GOV-T6 (#6679) or any baseline item.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the labeled lines in GrpcParser.java, DubboIngressParser.java, and SofaParser.java, then trace how each parser obtains ingress labels and referenced Services. Handle missing labels and missing Services without dereferencing null values. Done means label-free or missing-Service ingresses no longer crash reconciliation and valid references still proceed to route configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.