Skip to content

Preserve nullable values in UseMapOf prose-map conversions - #1204

Open
martinfrancois wants to merge 1 commit into
openrewrite:mainfrom
martinfrancois:agent/repro-use-map-of-nullable-value
Open

Preserve nullable values in UseMapOf prose-map conversions#1204
martinfrancois wants to merge 1 commit into
openrewrite:mainfrom
martinfrancois:agent/repro-use-map-of-nullable-value

Conversation

@martinfrancois

@martinfrancois martinfrancois commented Aug 15, 2026

Copy link
Copy Markdown

Suggested review order: 2 of 52 (Score: 9)
Review first: openrewrite/rewrite#8508

What's changed?

Restricts staged HashMap conversion to entries whose keys and values are proven non-null. Unknown reference expressions remain unchanged, while values whose non-nullness follows from their expression shape remain eligible.

What's your motivation?

Recipe: org.openrewrite.java.migrate.util.UseMapOf.

I found this by running org.openrewrite.java.migrate.util.UseMapOf from org.openrewrite.recipe:rewrite-migrate-java:3.40.0 on PromptRenderer.java in Symphony-Trello at a8013f27. I reproduced the same result with the latest released recipe artifact, org.openrewrite.recipe:rewrite-migrate-java:3.42.0. The original target test passes. After the recipe, WorkflowConfigPromptTest.missingWorkflowAndUnknownTemplateVariablesUseTypedErrors fails because attempt == null reaches Map.of and throws NullPointerException before the expected application error is created.

Before

Map<String, Object> context = new HashMap<>();
context.put("card", cardData);
context.put("issue", cardData);
context.put("attempt", attempt);

Actual after the recipe

Map<String, Object> context = new HashMap<>(Map.of(
        "card", cardData,
        "issue", cardData,
        "attempt", attempt));

Expected after the recipe

(unchanged)

HashMap.put accepts null values, while Map.of rejects them. The recipe silently changes the first-attempt runtime behavior from a typed application error to NullPointerException.

Confirmed real-world execution

Anything in particular you'd like reviewers to focus on?

Please review the conservative non-null proof. An expression with unknown nullability remains unchanged instead of being treated as non-null without data-flow evidence.

Have you considered any alternatives or workarounds?

Adding a sentinel for null would change the application's prompt contract. Leaving only the unsafe conversion unchanged preserves behavior without changing the recipe's safe cases.

Any additional context

Pre-existing tests changed: None.

This change was prepared with AI assistance. I reviewed the target execution evidence, implementation, tests, and contribution text.

Checklist

@martinfrancois
martinfrancois force-pushed the agent/repro-use-map-of-nullable-value branch from fba4ead to 0e7b899 Compare August 16, 2026 02:53
@martinfrancois
martinfrancois marked this pull request as ready for review August 17, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant