Skip to content

HADOOP-20020. DNS.reverseDns throws NullPointerException when the answer has no PTR record - #8820

Merged
smengcl merged 2 commits into
apache:trunkfrom
smengcl:HADOOP-20020
Oct 15, 2026
Merged

smengcl merged 2 commits into
apache:trunkfrom
smengcl:HADOOP-20020

Conversation

@smengcl

@smengcl smengcl commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Generated-by: Claude Code (Opus 5.5)

Description of PR

DNS.reverseDns reads attribute.get("PTR").get() without a null check. When a DNS server answers the reverse query with NOERROR but no PTR record (a NODATA answer), JNDI returns no PTR attribute and reverseDns throws NullPointerException. Its callers, DNS.getHosts and DNSDomainNameResolver.getHostnameByIP, only catch NamingException, so the exception escapes instead of falling back. Through getHostnameByIP it reaches SecurityUtil.getServerPrincipal(String, InetAddress) and ServiceAuthorizationManager.authorize.

This PR throws NameNotFoundException in that case, the exception JNDI already throws when the name does not exist (NXDOMAIN). Answers that carry a PTR record are handled as before. IPv4 and IPv6 addresses are affected alike.

How was this patch tested?

Added TestDNS#testReverseDnsWithoutPtrRecord. It starts a small DNS responder on a loopback UDP port that answers every query with NOERROR and no records, and checks that the reverse lookup of an IPv4 and an IPv6 address fails with NameNotFoundException. On trunk the test fails with the NullPointerException.

mvn test -Dtest='TestDNS,TestSecurityUtil,TestNetUtils' in hadoop-common with JDK 17: 91 tests run, 0 failures, 0 errors, 0 skipped.

For code changes:

  • Does the title of this PR start with the corresponding JIRA issue id (e.g. 'HADOOP-17799. Your PR title ...')?
  • Object storage: Have the integration tests been executed and the endpoint
    declared according to the connector-specific documentation? Note: Automated CI
    testing doesn't cover all cases so manual testing with cloud storage is still
    required.
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE, LICENSE-binary, NOTICE-binary files?

AI Tooling

Contains content generated by Claude Code.

🤖 Generated with Claude Code

…wer has no PTR record

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings October 14, 2026 09:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open findings
What changed in this PR

Fixes DNS.reverseDns to avoid NullPointerException when DNS responds with NOERROR but no PTR (NODATA), and adds a regression test to validate the new behavior.

Changes:

  • Treat missing PTR attribute in reverse DNS responses as NameNotFoundException (instead of triggering an NPE).
  • Add a UDP-based test DNS responder to simulate NOERROR-without-records for both IPv4 and IPv6.
File Description
hadoop-common-project/​hadoop-common/​src/​main/​java/​org/​apache/​hadoop/​net/​DNS.java Adds null-check for PTR attribute and throws NameNotFoundException for NODATA reverse lookups.
hadoop-common-project/​hadoop-common/​src/​test/​java/​org/​apache/​hadoop/​net/​TestDNS.java Adds regression test and minimal DNS responder that returns NOERROR with no records.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hadoop-yetus

This comment was marked as outdated.

@hadoop-yetus

Copy link
Copy Markdown

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 19m 17s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+1 💚 mvninstall 47m 59s trunk passed
+1 💚 compile 16m 24s trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 compile 17m 0s trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 checkstyle 1m 33s trunk passed
+1 💚 mvnsite 2m 1s trunk passed
+1 💚 javadoc 1m 34s trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javadoc 1m 30s trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 spotbugs 3m 11s trunk passed
+1 💚 shadedclient 31m 11s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 14s the patch passed
+1 💚 compile 15m 42s the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javac 15m 42s the patch passed
+1 💚 compile 16m 44s the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 javac 16m 44s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 1m 31s the patch passed
+1 💚 mvnsite 2m 2s the patch passed
+1 💚 javadoc 1m 29s the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javadoc 1m 28s the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 spotbugs 3m 21s the patch passed
+1 💚 shadedclient 31m 36s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 23m 49s hadoop-common in the patch passed.
+1 💚 asflicense 1m 17s The patch does not generate ASF License warnings.
243m 23s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8820/2/artifact/out/Dockerfile
GITHUB PR #8820
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 2359a74d25b9 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / ae72666
Default Java Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8820/2/testReport/
Max. process+thread count 3151 (vs. ulimit of 10000)
modules C: hadoop-common-project/hadoop-common U: hadoop-common-project/hadoop-common
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8820/2/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@slfan1989 slfan1989 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

The fix correctly routes missing PTR responses through the existing NamingException fallback handling.

I verified that the new regression test passes with this change and fails with the original NullPointerException without it.

The latest CI checks are green. +1.

@smengcl

smengcl commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @slfan1989 for the review.

@smengcl
smengcl merged commit df8e2a7 into apache:trunk Oct 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants