Fatal Error in user_ldap

Hello community, I have an issue with nextcloud. I tried to update an old owncloud version (Version 8.2.11) to nextcloud (Version 9.0.57). If it works I want to update to the latest stable version.
The problem seems to be in the ldap app.
Error:

PHP Fatal error: Call to a member function getUsername() on a non-object in /var/www/datacenter/owncloud/apps/user_ldap/user_ldap.php on line 89

This is the message in the Log:
“No or empty name for cn=ps, cn=role baser service 2,o=xxx”

Steps to reproduce

  1. Download latest Nextcloud (Version 9.0.57)
  2. Replace file except data and config
  3. Start upgrade via console

Expected behaviour

Successful update

Actual behaviour

sudo -u www-data php occ upgrade
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
Set log level to debug
Turned on maintenance mode
Checking whether the database schema can be updated (this can take a long time depending on the database size)
Checked database schema update
Checking updates of apps
Checking whether the database schema for <activity> can be updated (this can take a long time depending on the database size)
Checking whether the database schema for <files_sharing> can be updated (this can take a long time depending on the database size)
Checking whether the database schema for <files_trashbin> can be updated (this can take a long time depending on the database size)
Checking whether the database schema for <user_ldap> can be updated (this can take a long time depending on the database size)
Checked database schema update for apps
Updating database schema
Updated database
Disabled 3rd-party app: updater
Updating <files_pdfviewer> ...
Updated <files_pdfviewer> to 0.8.1
Updating <files_texteditor> ...
Updated <files_texteditor> to 2.1
Updating <gallery> ...
Updated <gallery> to 14.5.0
Updating <user_ldap> ...
Updated <user_ldap> to 0.8.0
Updating <files> ...
Updated <files> to 1.4.4
Updating <activity> ...
Updated <activity> to 2.2.1
Updating <files_sharing> ...
Updated <files_sharing> to 0.9.1
Updating <files_trashbin> ...
Updated <files_trashbin> to 0.8.0
Updating <files_versions> ...
Updated <files_versions> to 1.2.0
PHP Fatal error:  Call to a member function getUsername() on a non-object in /var/www/datacenter/owncloud/apps/user_ldap/user_ldap.php on line 89

Server configuration

Operating system:
Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.82-1 x86_64 GNU/Linux

Web server:
nginx version: nginx/1.10.1

Database:
mysql Ver 14.14 Distrib 5.5.52, for debian-linux-gnu (x86_64) using readline 6.2

PHP version:
PHP 5.5.38-1~dotdeb+7.1 (cli) (built: Jul 21 2016 18:33:48)
Copyright © 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright © 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright © 1999-2015, by Zend Technologies

Nextcloud version: (see Nextcloud admin page)
Version 9.0.57
Updated from an older Nextcloud/ownCloud or fresh install:
owcnloud Version 8.2.11

Where did you install Nextcloud from:
console, downloaded form official website

List of activated apps:

App list
nabled:
  - activity: 2.2.1
  - comments: 0.2
  - dav: true
  - federatedfilesharing: true
  - federation: 0.0.4
  - files: 1.4.4
  - files_pdfviewer: 0.8.1
  - files_sharing: 0.9.1
  - files_texteditor: 2.1
  - files_trashbin: 0.8.0
  - files_versions: 1.2.0
  - gallery: 14.5.0
  - provisioning_api: 0.4.1
  - templateeditor: 0.1
  - theming: 0.2.0
  - user_ldap: 0.8.0
Disabled:
  - admin_audit
  - encryption
  - external
  - files_external
  - files_videoplayer
  - firstrunwizard
  - notifications
  - password_policy
  - systemtags
  - updatenotification
  - user_external
  - user_saml

Nextcloud configuration:

Config report
{
    "system": {
        "installed": true,
        "dbtype": "mysql",
        "dbname": "datacenter",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "localhost",
        "dbtableprefix": "oc_",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "forcessl": true,
        "blacklisted_files": [
            ".htaccess"
        ],
        "overwritehost": "",
        "overwriteprotocol": "",
        "overwritewebroot": "",
        "overwritecondaddr": "",
        "proxy": "10.50.1.4:8081",
        "proxyuserpwd": "",
        "trusted_domains": [
           
            "ssfdsfdsf.ifdsafdsafdsfd.com"
        ],
        "theme": "",
        "default_language": "en",
        "3rdpartyroot": "",
        "3rdpartyurl": "",
        "defaultapp": "files",
        "knowledgebaseenabled": true,
        "appstoreenabled": false,
        "appstoreurl": "https:\/\/api.owncloud.com\/v1",
        "mail_domain": "yyyc.om,
        "mail_from_address": "zzzzzz",
        "mail_smtpdebug": false,
        "mail_smtpmode": "smtp",
        "mail_smtphost": "xxxx.yyyy.com",
        "mail_smtpport": "25",
        "mail_smtptimeout": 10,
        "memcached_servers": [
            [
                "localhost",
                11211
            ]
        ],
        "trashbin_retention_obligation": "30, auto",
        "allow_user_to_change_display_name": true,
        "appcodechecker": true,
        "updatechecker": true,
        "has_internet_connection": true,
        "check_for_working_webdav": true,
        "check_for_working_htaccess": true,
        "log_type": "owncloud",
        "logfile": "owncloud.log",
        "loglevel": 0,
        "logdateformat": "F d, Y H:i:s",
        "logtimezone": "Europe\/Berlin",
        "log_query": false,
        "cron_log": true,
        "log_rotate_size": false,
        "remember_login_cookie_lifetime": 1296000,
        "session_lifetime": 86400,
        "session_keepalive": true,
        "custom_csp_policy": "default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-src *; img-src *; font-src 'self' data:; media-src *",
        "xframe_restriction": true,
        "maintenance": true,
        "customclient_desktop": "",
        "customclient_android": "",
        "customclient_ios": "",
        "enable_previews": true,
        "preview_max_scale_factor": 10,
        "preview_libreoffice_path": "\/usr\/bin\/libreoffice",
        "preview_office_cl_parameters": "",
        "enable_avatars": true,
        "openssl": [],
        "cipher": "AES-256-CFB",
        "singleuser": false,
        "asset-pipeline.enabled": false,
        "mount_file": "",
        "cache_path": "",
        "quota_include_external_storage": false,
        "filesystem_check_changes": 1,
        "filesystem_cache_readonly": false,
        "share_folder": "\/",
        "instanceid": "ocb88044f685",
        "version": "8.2.11.1",
        "datadirectory": "\/var\/www\/datacenter\/data",
        "ldapIgnoreNamingRules": false,
        "secret": "***REMOVED SENSITIVE VALUE***"
    }
}

Are you using external storage, if yes which one: local/smb/sftp/…
no
Are you using encryption: yes/no
no
Are you using an external user-backend, if yes which one: LDAP/ActiveDirectory/Webdav/…
ldap

LDAP configuration (delete this part if not used)

LDAP config
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade

                                                                  
  [Symfony\Component\Console\Exception\CommandNotFoundException]  
  There are no commands defined in the "ldap" namespace.          
                                                                  


Nextcloud log (data/nextcloud.log)

Nextcloud log
{"reqId":"kuucUsINknBTAVqGETlM","remoteAddr":"","app":"user_ldap","message":"Requested attribute fullname not found for cn=ps,cn=role based service 2,o=<ORG>","level":0,"time":"October 08, 2017 16:31:38","method":"--","url":"--","user":"--","version":"8.2.11.1"}
{"reqId":"kuucUsINknBTAVqGETlM","remoteAddr":"","app":"user_ldap","message":"No or empty name for cn=ps,cn=role based service 2,o=<ORG>.","level":1,"time":"October 08, 2017 16:31:38","method":"--","url":"--","user":"--","version":"8.2.11.1"}
{"reqId":"kuucUsINknBTAVqGETlM","remoteAddr":"","app":"PHP","message":"Call to a member function getUsername() on a non-object at \/var\/www\/datacenter\/owncloud\/apps\/user_ldap\/user_ldap.php#89","level":3,"time":"October 08, 2017 16:31:38","method":"--","url":"--","user":"--","version":"8.2.11.1"}

....

I will try the solution from @blizzz an will post the result later

if($user instanceof OfflineUser) {

to

if($user === null || $user instanceof OfflineUser) {