7 Replies Latest reply on Nov 16, 2007 5:29 AM by wolfc

    Metamodel and collections

    anil.saldhana

      I see that the new meta model is returning null rather than an empty collection. This would require an explicit check for null.

      Examples:
      JBossAssemblyDescriptorMetaData.getApplicationExceptions
      SecurityRoleMetaData.getPrincipals

        • 1. Re: Metamodel and collections
          wolfc

           

          java.lang.NullPointerException
           at org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData.getPrincipalVersusRolesMap(JBossAssemblyDescriptorMetaData.java:360)
           at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:159)
          

          Code with an explicit check on null is twice as fast. So I would save 1ms for every ~100000 calls. :-)

          Seriously: the code in getPrincipalVersusRolesMap is too slow for per EJB call usage. I would rather see the reversed mapping being dynamically maintained in SecurityRolesMetaData.

          • 2. Re: Metamodel and collections

             

            "wolfc" wrote:

            Code with an explicit check on null is twice as fast. So I would save 1ms for every ~100000 calls. :-)


            More importantly referencing an empty collection uses more memory and slows down
            garbage collection.

            If only the new for() loop checked for null and didn't iterate instead of throwing an NPE. ;-)

            • 3. Re: Metamodel and collections
              wolfc

              I'll fix the lot.

              • 4. Re: Metamodel and collections
                anil.saldhana

                 

                "adrian@jboss.org" wrote:
                "wolfc" wrote:

                Code with an explicit check on null is twice as fast. So I would save 1ms for every ~100000 calls. :-)

                If only the new for() loop checked for null and didn't iterate instead of throwing an NPE. ;-)


                Yes, the enhanced for loop should have been checking for nulls.

                • 5. Re: Metamodel and collections
                  anil.saldhana

                   

                  "wolfc" wrote:
                  java.lang.NullPointerException
                   at org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData.getPrincipalVersusRolesMap(JBossAssemblyDescriptorMetaData.java:360)
                   at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:159)
                  

                  Code with an explicit check on null is twice as fast. So I would save 1ms for every ~100000 calls. :-)

                  Seriously: the code in getPrincipalVersusRolesMap is too slow for per EJB call usage. I would rather see the reversed mapping being dynamically maintained in SecurityRolesMetaData.


                  You are right. That map needs to be generated one time during deployment and accessed multiple times. I see that you made the changes. Is this what you did?

                  • 6. Re: Metamodel and collections
                    wolfc

                    Yup.

                    • 7. Re: Metamodel and collections
                      wolfc

                      Deeper into the empty collections we can have silly mergers:
                      http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas?view=rev&revision=67166

                      Somewhere the empty collection should not have been created in the first place.