Getting 'entityNameToMatch argument cannot be null' error in the logs

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

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:

1 2 3 4 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:

1 $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:

    1 2 3 4 #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:

    1 2 3 4 5 #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)

Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.