• org.openntf.domino.impl.Database instanceof Map

    By Bjørn Tore Olsen Cintra 1 decade ago

    I have a problem using the org.openntf api together with Freemarker, and specifically with Database. It ssems the Database implementation is an instance of Map (as it extends Map

    Freemarker (a templating language) has a feature where it wraps "native" objects into objects it can use in the templates.

    When i access the database with freemarker ( ${database} ), a get() method is called, the type is checked, wrapped, and the object is returned. If the object is an instance of Map, it will call new HashMap(Map obj). Since Database is an instance of Map, this gets called, the java.util.HashMap constructor doesn't understand the object it is getting, and barfs, thereby returning a NullPointerException.

    I understand why this is done in the org.openntf API, but I question if it is correct, and can anything be done with it?

    Bjørn Cintra

     

    • Ha!

      By Jesse Gallagher 1 decade ago

      Yikes! I guess it's actually a good thing I didn't implement the proper Map methods for traversing the contents - otherwise, the "new HashMap" line would open every document in the database.

      The change didn't make it into M3, but I plan to reverse my poor decision to make Database implement Map directly (it has negative consequences with EL use as well, though less hilariously so). I plan to, instead, create a method like "database.getDocumentMap()" that will instead return a Map view of the database and, when I implement that, I will also implement the remaining applicable Map methods properly.

      • That was going to be my suggestion :)

        By Bjørn Tore Olsen Cintra 1 decade ago

        However for Freemarker, I am able to override the DefaultObjectWrapper with my own, so my problem is taken care of.

        Btw, if I want to add suggestions, report bugs, etc, is this the place, or do you prefer Github?

        I am currently migrating my (rather large) project to org.openntf.domino, so I expect some issues ;)

         

        Bjørn

        • Both work - Github is better

          By Jesse Gallagher 1 decade ago

          We get notification emails for topics in either place, but GitHub is all the nicer - that way, we can mark commits as pertaining to specific issues, at least when we remember (which I know I, for one, rarely do).