Skip to content

Handle null dynamic keys in lookup helper - #1198

Merged
jknack merged 1 commit into
jknack:masterfrom
curforever:fix/lookup-null-key
Oct 24, 2026
Merged

jknack merged 1 commit into
jknack:masterfrom
curforever:fix/lookup-null-key

Conversation

@curforever

Copy link
Copy Markdown
Contributor

Fixes #1060.

lookup obj person.id currently throws a NullPointerException when the dynamic key resolves to null. LookupHelper dereferences the parameter with toString() before checking that case.

Treat a null key like an absent lookup parameter: return the original context. This preserves this Java helper's existing fallback for absent parameters and missing/null lookup results. A literal string "null" still names a property; non-null lookups are unchanged.

Validation on Windows / Microsoft OpenJDK 21.0.12 / Maven 3.9.11, with the original Java 17 release target and POM:

  • The same 16 regression tests: six NPE failures/errors before, all pass after. Includes direct helper calls and real nested/each/subexpression template rendering, plus existing fallback and false/zero/empty-result controls.
  • Changed-file Spotless check passes.
  • mvn -B -ff -ntp clean install: 1192 passing, 3 default skipped, zero failures/errors.
  • mvn -B -ff -ntp clean package: 1192 passing, 3 default skipped, zero failures/errors.

The Mustache spec submodule was checked out at its pinned gitlink. No POM/test exclusions or skip flags were added; repeated builds are not additional distinct tests. The 3 existing skips are one Mustache partial Failed Lookup spec case and two opt-in benchmark cases. No benchmark result is claimed.

Core Javadoc generation reports No source files for package com.github.jknack.handlebars.cache. The unchanged upstream POM already sets maven.javadoc.failOnError=false, so the default build exits with status 0 and downstream doc-link errors are ignored. Replaying the generated Javadoc arguments against original and fixed sources produced exit status 2 and the same error. Documentation generation is not claimed to pass.

Other OS/JDK matrix cells were not run locally.

Prepared with assistance from OpenAI Codex; validation commands above were run locally.

@jknack jknack added this to the 4.5.6 milestone Oct 24, 2026
@jknack
jknack merged commit a3a3976 into jknack:master Oct 24, 2026
4 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.

com.github.jknack.handlebars.helper.LookupHelper NullPointerException

2 participants