Skip to content

Conversation

@andras-markos
Copy link
Contributor

@andras-markos andras-markos commented Aug 21, 2025

Supersedes #58; this PR contains only the fix.

This fixes var resolution so a default is applied only when the path is missing, not when the value is explicitly null.

Why

Per the JsonLogic docs, the second var argument is a default “for values that might be missing.” Treating null as missing deviates from that intent and leads to surprising results.

What changed

  • Introduced an internal MISSING sentinel to track “not found” during path traversal.
  • Map access now uses containsKey to differentiate an absent key from a present key with null.
  • Array access returns MISSING for out-of-bounds indices.
  • evaluate(JsonLogicVariable, …) applies the default only when the traversal yields MISSING; explicit null is returned as null.

Examples

  • {"var": ["user.age", 42]} with {"user":{"age": null}}null (no default)
  • {"var": ["items.2", "missing"]} with {"items":[10,20]}"missing"
  • {"var": ""} returns the entire data object (same instance)

Tests

Added coverage to VariableTests:

  • Missing nested key falls back to default.
  • Present leaf null returns null (no default).
  • Intermediate null or non-traversable types return null.
  • Array index in-bounds returns the element; out-of-bounds uses default.
  • Top-level numeric index over lists works.
  • Empty var key returns the original data object.

Compatibility

Behavior change for callers who relied on “default-for-null.” This aligns with the JsonLogic spec and other interpreters.

@andras-markos andras-markos changed the title Fix: treat null differently from missing Fix: Distinguish missing vs null in var resolution (use default only when missing) Aug 21, 2025
@andras-markos
Copy link
Contributor Author

This PR now only contains the changes I originally intended.

@jamsesso jamsesso merged commit 49995a7 into jamsesso:main Sep 7, 2025
1 check passed
@andras-markos
Copy link
Contributor Author

@jamsesso It seems the publish package step failed:
Could not transfer artifact io.github.jamsesso:json-logic-java:jar:1.1.1 from/to remote (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Access denied to: https://oss.sonatype.org/service/local/staging/deploy/maven2/io/github/jamsesso/json-logic-java/1.1.1/json-logic-java-1.1.1.jar, ReasonPhrase: Forbidden.

@andras-markos
Copy link
Contributor Author

@jamsesso It seems the publish package step failed: Could not transfer artifact io.github.jamsesso:json-logic-java:jar:1.1.1 from/to remote (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Access denied to: https://oss.sonatype.org/service/local/staging/deploy/maven2/io/github/jamsesso/json-logic-java/1.1.1/json-logic-java-1.1.1.jar, ReasonPhrase: Forbidden.

@jamsesso Could you please take a look?

@andras-markos
Copy link
Contributor Author

@jamsesso It seems the publish package step failed: Could not transfer artifact io.github.jamsesso:json-logic-java:jar:1.1.1 from/to remote (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Access denied to: https://oss.sonatype.org/service/local/staging/deploy/maven2/io/github/jamsesso/json-logic-java/1.1.1/json-logic-java-1.1.1.jar, ReasonPhrase: Forbidden.

@jamsesso Could you please take a look?

Is there any chance you could look into the publish package failure?

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.

2 participants