konsoletyper/teavm-flavour

non-expected null pointer?

teras opened this issue · 2 comments

teras commented

I think I have found an issue where a non-expected null pointer appers.

I have created a minimum test to support it.

So, let's first define two classes:

   @BindTemplate("templates/test.html")
   public class Test extends ApplicationTemplate {
      final List<Data> data;

      public Test() {
        data = Arrays.asList(new Data("1"), new Data(("2")));
      }

    public List<Data> cursor() {
        return data;
     }
   }

class Data {
  final String name;

    public Data(String name) {
      this.name = name;
    }
    public String getName() {
       return name;
    }
}

and under templates/test.html

    init
    <std:foreach var="item" index="i" in="cursor()">
         <html:text value="item.name"/>
         <br/>
    </std:foreach>

I wouldn't expect any null pointer, since all has been initialized in advance - so why this happens?

Hello. Could not reproduce. Can you provide a full example, including build configuration and main class, as a zip file? So that I could unpack it and run 'mvn package' to build without any other setup from my side.

teras commented

I am sorry I wasn't quick enough to close it
Rubber duck debugging to the rescue: I found the issue and it is totally my fault.

I was trying to instantiate a class, where in the parent contructor I was trying to bind it at the same time, of course while the data wasn't available yet.

I am so sorry for this -- keep up the good work and thank you for this awesome project of yours.

(PS maybe I should delete this issue... if possible...)