Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-17595

NPE when using api.User.isUserInGroup for the guest user

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 11.10.4
    • Fix Version/s: 12.6.1, 11.10.10, 12.7-rc-1
    • Component/s: Old Core
    • Labels:
      None
    • Difficulty:
      Unknown
    • Documentation:
      N/A
    • Documentation in Release Notes:
      N/A
    • Similar issues:

      Description

      I see often errors in the logs about this NPE when the XWikiGuest user is checked if it is part of a group:

      WARN  c.x.x.a.User                   - Unhandled exception while checking if user XWiki.XWikiGuest belongs to group XWiki.XWikiDevGroup 
      java.lang.NullPointerException: null
              at com.xpn.xwiki.user.impl.xwiki.XWikiGroupServiceImpl.getAllGroupsReferencesForMember(XWikiGroupServiceImpl.java:756)
              at com.xpn.xwiki.user.api.XWikiUser.isUserInGroup(XWikiUser.java:398)
              at com.xpn.xwiki.api.User.isUserInGroup(User.java:124)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      ...
      

      Can be reproduced by executing with a guest user the following:

      $xwiki.getUser().isUserInGroup('XWiki.XWikiAllGroup')
      

      It would seem that the check we had for null users (like it would sound reasonable for guest users) does no longer apply. For XWikiGuest users, the api.User object is initialized with an XWikiUser object having a null DocumentReference, while the check expected it to be initialized with a null XWikiUser object altogether. https://github.com/xwiki/xwiki-platform/blob/fc1ca29a2d829e7b9fb0b7fb2c0cdad6433675b0/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/User.java#L121

        Attachments

          Activity

            People

            Assignee:
            tmortagne Thomas Mortagne
            Reporter:
            enygma Eduard Moraru
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Date of First Response: