Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE for loop tuple vars of null. #1164

Merged
merged 1 commit into from
Mar 5, 2024
Merged

Fix NPE for loop tuple vars of null. #1164

merged 1 commit into from
Mar 5, 2024

Conversation

hs-lsong
Copy link
Collaborator

@hs-lsong hs-lsong commented Mar 4, 2024

If the a loop value is null, we should not try to get the .getClass() of it. It throws a NPE. We fixed this for single var loops, did not expect this also happens for tuples.

A bad jinjava tag can trigger it:

{% for  for row in module.specific_projects  %}

@hs-lsong hs-lsong requested a review from jasmith-hs March 4, 2024 21:52
Copy link
Contributor

@jasmith-hs jasmith-hs left a comment

Choose a reason for hiding this comment

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

This change looks good, but my concern about NullValue from #1147 (comment) and #1140 (comment) still exists

Comment on lines +219 to +226
if (
interpreter.getContext().get(loopVar) != null &&
interpreter.getConfig().getLegacyOverrides().isKeepNullableLoopValues()
) {
interpreter.getContext().put(loopVar, NullValue.INSTANCE);
} else {
interpreter.getContext().put(loopVar, null);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This and L#208-214 can be extracted to a single method.

@hs-lsong hs-lsong merged commit 3fa1fa1 into master Mar 5, 2024
5 checks passed
@hs-lsong hs-lsong deleted the fix-tuple-nulls branch March 5, 2024 14:02
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