Skip to content

Handle null dynamic keys in lookup helper - #1198

Open
curforever wants to merge 1 commit into
jknack:masterfrom
curforever:fix/lookup-null-key
Open

curforever wants to merge 1 commit into
jknack:masterfrom
curforever:fix/lookup-null-key

Conversation

@curforever

Copy link
Copy Markdown

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.

This branch has not been deployed

No deployments
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.

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

1 participant