Skip to content

fix: prevent NullPointerException when property is null in VariableReferenceExpression - #2394

Merged
lbroudoux merged 2 commits into
microcks:masterfrom
aryarathoree:fix/variable-reference-null-property
Nov 9, 2026
Merged

lbroudoux merged 2 commits into
microcks:masterfrom
aryarathoree:fix/variable-reference-null-property

Conversation

@aryarathoree

Copy link
Copy Markdown
Contributor

Description

When a property reference evaluates to null (e.g., request.body/id when request.body is null), VariableReferenceExpression.getValue() throws a NullPointerException when calling variableValue.getClass().

This PR fixes both cases described in #2392:

  1. No default: A missing property evaluates to null and renders as the string "null".
  2. With fallback (||): A missing property evaluates to null, allowing FallbackExpression to use the provided default (e.g., 'default').

Additionally:

  • Added a null check in getProperty(obj, property) to prevent a secondary NullPointerException when logging warnings for a null object.
  • Added end-to-end tests in TemplateEngineTest, along with unit tests in VariableReferenceExpressionTest and FallbackExpressionTest.

Related issue(s)

Fixes #2392

Testing

Ran the microcks-el test suite:

[INFO] Results:
[INFO] Tests run: 48, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS

…ariableReferenceExpression

Check for null variableValue before evaluating path expressions so that templates safely render null and fallback expressions can proceed. Also guard getProperty against null object and property references.

Signed-off-by: Arya Rathore <[email protected]>
…eferenceExpression

Verify that null properties with path queries render null and allow fallback expressions to be evaluated, both in isolated expression tests and end-to-end TemplateEngine tests.

Signed-off-by: Arya Rathore <[email protected]>

@lbroudoux lbroudoux left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thank you!

@lbroudoux
lbroudoux merged commit 459a69b into microcks:master Nov 9, 2026
13 checks passed
lbroudoux pushed a commit that referenced this pull request Nov 12, 2026
…ferenceExpression (#2394)

* fix(util-el): prevent NullPointerException when property is null in VariableReferenceExpression

Check for null variableValue before evaluating path expressions so that templates safely render null and fallback expressions can proceed. Also guard getProperty against null object and property references.

Signed-off-by: Arya Rathore <[email protected]>

* test(util-el): add unit tests for null property handling in VariableReferenceExpression

Verify that null properties with path queries render null and allow fallback expressions to be evaluated, both in isolated expression tests and end-to-end TemplateEngine tests.

Signed-off-by: Arya Rathore <[email protected]>

---------

Signed-off-by: Arya Rathore <[email protected]>
(cherry picked from commit 459a69b)
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.

[BUG] VariableReferenceExpression: prevent NullPointerException when property is null

2 participants