samskivert / jmustache

A Java implementation of the Mustache templating language.
Other
834 stars 128 forks source link

Null context for variable '.' though I have a null check #96

Closed Pasupathi-Rajamanickam closed 6 years ago

Pasupathi-Rajamanickam commented 6 years ago

I'm using mustache compiler in spring-boot. Getting this weird exceptions though my mustache has null check.

{tableData={headers=[Name, Selector], records=[[1, null], [2, null]]}}

{{#tableData}}
<table class="table {{#tableClass}}{{.}}{{/tableClass}}">
<tr>
{{#headers}}
<th>{{.}}</th>
{{/headers}}
</tr>
{{#records}}
<tr>
{{#.}}
<td>{{#.}}{{.}}{{/.}}</td>
{{/.}}
</tr>
{{/records}}
</table>
{{/tableData}}

I have null check for {{#.}}{{.}}{{/.}} but still it throws java.lang.NullPointerException: Null context for variable '.' on line 11

samskivert commented 6 years ago

Turns out there was a bug in handling null inside of lists/iterables. This is fixed in 4533567303c5dd061b2925f30730a2b2b3fb1f34.

Apologies for taking a long time to investigate. Busy busy! :)

Pasupathi-Rajamanickam commented 6 years ago

@samskivert You did have if (name == "entrySet") :scream: I used to do this mistake when I work on java and javascript in parallel :rofl:

samskivert commented 6 years ago

I used to intern the key strings, so that was actually a safe thing to do. But I discovered that interning was really slow, so I changed the code not to do that two commits ago. But I missed a couple of spots where == was still being used.

So it was bad code, but not that bad. :) On Mon, Jun 4, 2018 at 5:06 PM Pasupathi Rajamanickam < notifications@github.com> wrote:

@samskivert https://github.com/samskivert You did have if (name == "entrySet") 😱

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/samskivert/jmustache/issues/96#issuecomment-394538372, or mute the thread https://github.com/notifications/unsubscribe-auth/AAL-9ChIZYUn1pfuDHNT7lI5D3IpP0e1ks5t5ct3gaJpZM4TDAOf .

-- -- mdb@samskivert.com