Skip to content

Fix NPE in currentNameMatch/nextNameMatch when PropertyNameMatcher is null [databind#5811]#1578

Closed
Copilot wants to merge 2 commits into3.xfrom
copilot/fix-npe-in-jackson-databind
Closed

Fix NPE in currentNameMatch/nextNameMatch when PropertyNameMatcher is null [databind#5811]#1578
Copilot wants to merge 2 commits into3.xfrom
copilot/fix-npe-in-jackson-databind

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

When ObjectMapper.convertValue() is used with a custom deserializer wrapping a BeanDeserializer, the inner deserializer's _nameMatcher can be null at deserialization time, causing an NPE when BeanDeserializer passes it to p.currentNameMatch(null).

Changes

  • ParserMinimalBase — null-guard in both currentNameMatch() and nextNameMatch(): return MATCH_UNKNOWN_NAME when matcher == null and current token is PROPERTY_NAME, allowing callers to fall back to slow-path string-based matching
  • UTF8StreamJsonParser — null-guard in the optimized nextNameMatch(): skip quad-based fast path, parse name normally, return MATCH_UNKNOWN_NAME
  • JsonParserSequence / FilteringParserDelegate — same null-guard in their nextNameMatch() overrides
  • NextNameWithMatcherTest — added @Test annotations (existing tests were not being discovered by JUnit 5), added testNullMatcherNextNameMatch and testNullMatcherCurrentNameMatch covering all parser modes

Behavior when matcher is null

Current token Return value
PROPERTY_NAME MATCH_UNKNOWN_NAME
END_OBJECT MATCH_END_OBJECT
anything else MATCH_ODD_TOKEN

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • central.sonatype.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.13/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.13/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.13 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.13/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/jackson-core/jackson-core org.codehaus.plexus.classworlds.launcher.Launcher test -pl . -Dtest=NextNameWithMatcherTest -q jackson/core/JsonParser.java jackson/core/it/ModuleInfoIT.java jackson/core/it/iptables jackson/core/uni-w jackson/core/uni-t jackson/core/unisecurity (dns block)
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /home/REDACTED/.m2/wrapper/dists/apache-maven-3.9.11/a2d47e15/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/home/REDACTED/.m2/wrapper/dists/apache-maven-3.9.11/a2d47e15/bin/m2.conf -Dmaven.home=/home/REDACTED/.m2/wrapper/dists/apache-maven-3.9.11/a2d47e15 -Dlibrary.jansi.path=/home/REDACTED/.m2/wrapper/dists/apache-maven-3.9.11/a2d47e15/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/jackson-core/jackson-core org.codehaus.plexus.classworlds.launcher.Launcher test -Dtest=NextNameWithMatcherTest -q (dns block)
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.13/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.13/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.13 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.13/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/jackson-core/jackson-core org.codehaus.plexus.classworlds.launcher.Launcher test -Dtest=NextNameWithMatcherTest -q --no-transfer-progress -Dmaven.repo.local=/home/REDACTED/.m2/repository (dns block)
  • https://api.github.com/repos/FasterXML/jackson-base/branches
    • Triggering command: /usr/bin/curl curl -s REDACTED (http block)
  • https://api.github.com/repos/FasterXML/jackson-base/contents/pom.xml
    • Triggering command: /usr/bin/curl curl -s REDACTED (http block)
  • https://api.github.com/repos/FasterXML/jackson-parent/branches
    • Triggering command: /usr/bin/curl curl -s REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…atabind#5811]

Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
Copilot AI changed the title [WIP] [JACKSON-5811] Fix NPE and add test coverage Fix NPE in currentNameMatch/nextNameMatch when PropertyNameMatcher is null [databind#5811] Mar 18, 2026
Copilot AI requested a review from pjfanning March 18, 2026 08:56
@cowtowncoder
Copy link
Copy Markdown
Member

No, this is wrong kind of defensive coding. Name matcher must be set and we should not sprinkle null checks all over codebase.

@pjfanning pjfanning closed this Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants