AnsweredAssumed Answered

New roles result in NullPointerExceptions in RoleComparator

Question asked by jevon on Feb 2, 2012
Latest reply on Feb 2, 2012 by mikeh
Following the instructions at Custom Permissions in Share, I was adding a number of additional roles, but when trying to login to Alfresco Share, the following server-side exception would occur:

2012-02-02 13:10:12,042  ERROR [extensions.webscripts.AbstractRuntime] [ajp-bio-8015-exec-35] Exception from executeScript - redirecting to status template error: 01020003 Wrapped Exception (with status template): 01020054 Error during processing of the template 'Method public java.lang.String org.alfresco.repo.site.script.Site.getMembersRole(java.lang.String) threw an exception when invoked on org.alfresco.repo.site.script.Site@4958b2cc'. Please contact your system administrator.
org.springframework.extensions.webscripts.WebScriptException: 01020003 Wrapped Exception (with status template): 01020054 Error during processing of the template 'Method public java.lang.String org.alfresco.repo.site.script.Site.getMembersRole(java.lang.String) threw an exception when invoked on org.alfresco.repo.site.script.Site@4958b2cc'. Please contact your system administrator.
        at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:971)
        at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
        at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:393)
        …
Caused by: org.alfresco.service.cmr.repository.TemplateException: 01020054 Error during processing of the template 'Method public java.lang.String org.alfresco.repo.site.script.Site.getMembersRole(java.lang.String) threw an exception when invoked on org.alfresco.repo.site.script.Site@4958b2cc'. Please contact your system administrator.
        at org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:206)
        at org.springframework.extensions.webscripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:801)
        at org.springframework.extensions.webscripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:267)
        at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:147)
        … 28 more
Caused by: freemarker.template.TemplateModelException: Method public java.lang.String org.alfresco.repo.site.script.Site.getMembersRole(java.lang.String) threw an exception when invoked on org.alfresco.repo.site.script.Site@4958b2cc
        at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
        …
Caused by: java.lang.NullPointerException
        at org.alfresco.repo.site.RoleComparatorImpl.compare(RoleComparatorImpl.java:39)
        at org.alfresco.repo.site.RoleComparatorImpl.compare(RoleComparatorImpl.java:24)
        at java.util.TreeMap.put(TreeMap.java:530)
        at java.util.TreeSet.add(TreeSet.java:238)
        at org.alfresco.repo.site.SiteServiceImpl.getMembersRole(SiteServiceImpl.java:1672)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)

On the client side, this would display as "Internal Server Error".

After some remote debugging, I think I found the problem. The issue is that the RoleComparator was not provided information about the precedence of these roles. In alfresco/WEB-INF/classes/alfresco/site-services-context.xml:

    <!–  Site role precedence - higher number - more important role –>    
    <bean id="siteRoleComparator" class="org.alfresco.repo.site.RoleComparatorImpl" init-method="init">
       <property name="rolePrecedence">
             <map>
                <entry key="SiteManager" value="4" />
                <entry key="SiteCollaborator" value="3" />
                <entry key="SiteContributor" value="2" />
                <entry key="SiteConsumer" value="1" />
             </map>
       </property>
    </bean>

Adding entries to this map solved this exception. I'm not sure if the documentation needs to be updated/clarified, or if the RoleComparatorImpl code should be made more robust?

Outcomes