Getting 'entityNameToMatch argument cannot be null' error in the logs
Problem
You have custom layouts or user macros in Confluence Admin >> Layouts
or Confluence Admin >> User Macros
And the following error appears in the atlassian-confluence.log
:
2013-04-23 01:32:36,054 ERROR [http-8080-21] [confluence.util.velocity.VelocityUtils] getRenderedContent Error occurred rendering template content
– url: /display/test9/test | page: 2222292 | userName: anonymous | action: viewpage
org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getGroupNamesForUserName' in class $Proxy31 threw exception
java.lang.IllegalArgumentException: entityNameToMatch argument cannot be null at getRenderedContent[line 84, column 40]
Cause
Any call to a function that expects a username argument ( $req.userPrincipal.name
) such as the following in any layouts (space or global level) or user macros:
$userAccessor.getGroupNamesForUserName($req.userPrincipal.name)
Notice that the function "getGroupNamesForUserName" is highlighted in the error above. The error will be thrown whenever an anonymous user tries to view the page that has that layout, or user macro.
Resolution
Look for any function calls that pass
$req.userPrincipal.name
as an argument, such as the user macro below:#set ($mygroupList = $userAccessor.getGroupNamesForUserName($req.userPrincipal.name)) #end Hello, $mygroupList , $req.userPrincipal.name
Check whether
$req.userPrincipal.name
is null before calling the function. Example:#if($req.userPrincipal.name) #set ($mygroupList = $userAccessor.getGroupNamesForUserName($req.userPrincipal.name)) #end Hello, $mygroupList , $req.userPrincipal.name
(add an if statement to check for null)