Skip to content

[util] Guard Taints.findTaint against null node spec/taints - #4958

Draft
yue9944882 wants to merge 1 commit into
kubernetes-client:masterfrom
yue9944882:fix/util-findtaint-npe
Draft

yue9944882 wants to merge 1 commit into
kubernetes-client:masterfrom
yue9944882:fix/util-findtaint-npe

Conversation

@yue9944882

Copy link
Copy Markdown
Member

Bug

Taints.findTaint(V1Node, String, Effect) iterates node.getSpec().getTaints() with no null check. For a node that has no spec (e.g. a freshly built V1Node), or whose taints list is explicitly null, this throws a NullPointerException instead of reporting that no matching taint exists.

This is inconsistent with the sibling removeTaint methods in the same class, which already guard a null spec and return gracefully — so findTaint was an oversight in null handling, not intended behavior.

Fix

Return null when the node has no spec or no taints list, before iterating. Minimal 3-line guard; no API/signature changes, no behavior change for nodes that do have taints.

Verification

./mvnw -pl util -am -Dtest=TaintsTest -Dsurefire.failIfNoSpecifiedTests=false test

  • Added focused test findTaintWithoutSpecReturnsNull.
  • Without the fix: the new test fails with the exact NPE (V1Node.getSpec() is null).
  • With the fix: Tests run: 4, Failures: 0, Errors: 0 — BUILD SUCCESS.

findTaint iterated node.getSpec().getTaints() with no null check, throwing
a NullPointerException for a node that has no spec (or whose taints list is
null) instead of reporting that no matching taint exists. The sibling
removeTaint methods already guard a null spec, so this was an inconsistent
null-safety gap. Return null when the spec or taints list is absent, and add
a focused unit test covering a node without a spec.
@kubernetes-prow kubernetes-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 22, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: yue9944882

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant