Buggy code:
; public static final String PARAM_USERID = "userid" ; private static final Log LOG = CmsLog . getLog ( A_CmsEditUserDialog . class ) ; private static final String PWD_OBJECT = "PWD_INFO" ; private static final String USER_OBJECT = "USER" ; protected CmsUser m_user ; private String m_group ; private String m_language ; private String m_paramOufqn ; private String m_paramUserid ; private CmsPasswordInfo m_pwdInfo ; private String m_site ; private String m_startFolder ; private String m_startProject ; private String m_startView ; private String m_role ; private static final String NO_ROLE = "NO_ROLE" ; public A_CmsEditUserDialog ( CmsJspActionElement jsp ) { } @ Override public void actionCommit ( ) { List < Throwable > errors = new ArrayList < Throwable > ( ) ; try { if ( isNewUser ( ) ) { CmsGroup group = null ; if ( CmsStringUtil . isNotEmptyOrWhitespaceOnly ( getGroup ( ) ) ) { group = getCms ( ) . readGroup ( getGroup ( ) ) ; } if ( group != null ) { if ( group . getSimpleName ( ) . equals ( OpenCms . getDefaultUsers ( ) . getGroupAdministrators ( ) ) ) { if ( getRole ( ) . equals ( A_CmsEditUserDialog . NO_ROLE ) ) { throw new org . opencms . main . CmsIllegalArgumentException ( Messages . get ( ) . container ( ERR_ADD_TO_ADMINISTRATORS_GROUP_0 ) ) ; } CmsRole role = CmsRole . valueOfRoleName ( getRole ( ) ) ; if ( ( ! ( ROOT_ADMIN . getRoleName ( ) . equals ( role . getRoleName ( ) ) ) ) && ( ! ( ADMINISTRATOR . getRoleName ( ) . equals ( role . getRoleName ( ) ) ) ) ) { throw new org . opencms . main . CmsIllegalArgumentException ( Messages . get ( ) . container ( ERR_ADD_TO_ADMINISTRATORS_GROUP_0 ) ) ; } } else if ( group . getSimpleName ( ) . equals ( OpenCms . getDefaultUsers ( ) . getGroupUsers ( ) ) ) { if ( getRole ( ) . equals ( A_CmsEditUserDialog . NO_ROLE ) ) { throw new org . opencms . main . CmsIllegalArgumentException ( Messages . get ( ) . container ( ERR_ADD_TO_USERS_GROUP_0 ) ) ; } } else if ( group . getSimpleName ( ) . equals ( OpenCms . getDefaultUsers ( ) . getGroupGuests ( ) ) ) { if ( ! ( getRole ( ) . equals ( A_CmsEditUserDialog . NO_ROLE ) ) ) { throw new org . opencms . main . CmsIllegalArgumentException ( Messages . get ( ) . container ( ERR_ADD_TO_GUESTS_GROUP_0 ) ) ; } } } m_pwdInfo . validate ( ) ; CmsUser newUser = createUser ( ( ( m_paramOufqn ) + ( m_user . getSimpleName ( ) ) ) , m_pwdInfo . getNewPwd ( ) , m_user . getDescription ( ) , m_user . getAdditionalInfo ( ) ) ; newUser . setFirstname ( m_user . getFirstname ( ) ) ; newUser . setLastname ( m_user . getLastname ( ) ) ; newUser . setEmail ( m_user . getEmail ( ) ) ; newUser . setAddress ( m_user . getAddress ( ) ) ; newUser . setManaged ( m_user . isManaged ( ) ) ; newUser . setEnabled ( m_user . isEnabled ( ) ) ; m_user = newUser ; } else if ( CmsStringUtil . isNotEmpty ( m_pwdInfo . getNewPwd ( ) ) ) { m_pwdInfo . validate ( ) ; getCms ( ) . setPassword ( m_user . getName ( ) , m_pwdInfo . getNewPwd ( ) ) ; } writeUser ( m_user ) ; if ( isNewUser ( ) ) { if ( CmsStringUtil . isNotEmptyOrWhitespaceOnly ( getGroup ( ) ) ) { getCms ( ) . addUserToGroup ( m_user . getName ( ) , getGroup ( ) ) ; } if ( ( CmsStringUtil . isNotEmptyOrWhitespaceOnly ( getRole ( ) ) ) && ( ! ( getRole ( ) . equals ( A_CmsEditUserDialog . NO_ROLE ) ) ) ) { <START_BUG> OpenCms . getRoleManager ( ) . addUserToRole ( getCms ( ) , CmsRole . valueOfRoleName ( getRole ( ) ) , m_user . getName ( ) ) ; <END_BUG> } } CmsUserSettings settings = new CmsUserSettings ( m_user ) ; settings . setLocale ( CmsLocaleManager . getLocale ( getLanguage ( ) ) ) ; settings . setStartSite ( getSite ( ) ) ; if ( isNewUser ( ) ) { settings . setStartProject ( ( ( getParamOufqn ( ) ) + ( getStartProject ( ) ) ) ) ; } else { settings . setStartProject ( getStartProject ( ) ) ; } boolean webuserOu = false ; try { webuserOu = OpenCms . getOrgUnitManager ( ) . readOrganizationalUnit ( getCms ( ) , getParamOufqn ( ) ) . hasFlagWebuser ( ) ; } catch ( CmsException e ) { } if ( ! webuserOu ) { CmsObject tmp = OpenCms . initCmsObject ( getCms ( ) ) ; tmp . getRequestContext ( ) . setSiteRoot ( getSite ( ) ) ; String folder = tmp . getRequestContext ( ) . removeSiteRoot ( getStartFolder ( ) ) ; try { CmsResource res = tmp . readResource ( folder ) ; String siteRoot = OpenCms . getSiteManager ( ) . getSiteRoot ( res . getRootPath ( ) ) ; if ( ( ( CmsStringUtil . isNotEmptyOrWhitespaceOnly ( siteRoot ) ) && ( CmsStringUtil . isNotEmptyOrWhitespaceOnly ( tmp . getRequestContext ( ) . getSiteRoot ( ) ) ) ) && ( ! ( tmp . getRequestContext ( ) . getSiteRoot ( ) . equals ( "//" ) ) ) ) { folder = res . getRootPath ( ) . substring ( siteRoot . length ( ) ) ; } } catch ( CmsException e ) { throw new org . opencms . main . CmsIllegalArgumentException ( Messages . get ( ) . container ( ERR_SELECTED_FOLDER_NOT_IN_SITE_0 ) ) ; } settings . setStartFolder ( folder ) ; } settings . setStartView ( getStartView ( ) ) ;

Fix:
OpenCms . getRoleManager ( ) . addUserToRole ( getCms ( ) , CmsRole . valueOfRoleName ( getRole ( ) ) . forOrgUnit ( m_paramOufqn ) , m_user . getName ( ) ) ;