Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency Injection for classes with array constructor parameter fails #10231

Closed
DrRSatzteil opened this issue Jul 13, 2018 · 6 comments
Closed
Labels

Comments

@DrRSatzteil
Copy link
Contributor

I just noticed that injecting classes with array parameters fails as the SimpleContainer tries to resolve the variable name as a class which will usually fail. On the screenshot you can see the problem when trying to inject an OC\DB\Connection into a mapper:

image

Moreover the log file only shows me an error that my service class is not found however the problem lies much deeper (service -> mapper -> OC\DB\Connection <-- Throws Exception) which makes it really hard to realize what the problem really is.

Steps to reproduce

  1. Create a mapper in your app that uses a OC\DB\Connection in the constructor
  2. Use the mapper as a constructor parameter in a controller or service
  3. Try to call the controller from a client and the server will fail to instantiate the controller

Expected behaviour

Probably it should try to create an instance with an empty array and create the mapper. Or probably the Connection class should not use arrays in the constructor in the first place.

Actual behaviour

Nextcloud fails to create an instance of your controller/service/mapper

Server configuration

Operating system:
Ubuntu 18.04

Web server:
Apache2

Database:
SQLite (Development machine)

PHP version:
7.1

Nextcloud version: (see Nextcloud admin page)
14

Updated from an older Nextcloud/ownCloud or fresh install:
Fresh install

Where did you install Nextcloud from:
Github

List of activated apps:

App list
Enabled:
  - accessibility: 1.0.1
  - cloud_federation_api: 0.0.1
  - comments: 1.4.0
  - dav: 1.5.4
  - documentmanager: 0.0.5
  - federatedfilesharing: 1.4.0
  - federation: 1.4.0
  - files: 1.9.0
  - files_sharing: 1.6.1
  - files_trashbin: 1.4.1
  - files_versions: 1.7.1
  - lookup_server_connector: 1.2.0
  - oauth2: 1.2.1
  - provisioning_api: 1.4.0
  - sharebymail: 1.4.0
  - systemtags: 1.4.0
  - theming: 1.5.0
  - twofactor_backupcodes: 1.3.0
  - updatenotification: 1.4.1
  - workflowengine: 1.4.0
Disabled:
  - admin_audit
  - contacts
  - encryption
  - files_external
  - testing
  - user_ldap

Nextcloud configuration:

Config report
{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "192.168.0.100"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "sqlite3",
        "version": "14.0.0.10",
        "overwrite.cli.url": "http:\/\/192.168.0.100:33492\/nextcloudserver",
        "installed": true
    }
}

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/...
No

Client configuration

Browser:
Chrome 67.0.3396.99

Operating system:
Windows 10

Logs

Web server error log

Web server error log
Nothing interesting in there

Nextcloud log (data/nextcloud.log)

Nextcloud log
{"reqId":"DcFpnvm4KDvZPtimCkaA","level":3,"time":"2018-07-13T10:19:21+00:00","remoteAddr":"192.168.0.220","user":"admin","app":"PHP","method":"GET","url":"\/nextcloudserver\/index.php\/apps\/documentmanager\/","message":"You are using a fallback implementation of the intl extension. Installing the native one is highly recommended instead. at \/projects\/nextcloudserver\/3rdparty\/patchwork\/utf8\/src\/Patchwork\/Utf8\/Bootup\/intl.php#18","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/67.0.3396.99 Safari\/537.36","version":"14.0.0.10"}
{"reqId":"zLUV9s43321TW6bviHLR","level":3,"time":"2018-07-13T10:19:21+00:00","remoteAddr":"192.168.0.220","user":"--","app":"PHP","method":"GET","url":"\/nextcloudserver\/cron.php","message":"You are using a fallback implementation of the intl extension. Installing the native one is highly recommended instead. at \/projects\/nextcloudserver\/3rdparty\/patchwork\/utf8\/src\/Patchwork\/Utf8\/Bootup\/intl.php#18","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/67.0.3396.99 Safari\/537.36","version":"14.0.0.10"}
{"reqId":"F4vRdpAOjDKpUB0zVj1f","level":3,"time":"2018-07-13T10:19:22+00:00","remoteAddr":"192.168.0.220","user":"admin","app":"index","method":"GET","url":"\/nextcloudserver\/index.php\/apps\/documentmanager\/organisations","message":{"Exception":"OCP\\AppFramework\\QueryException","Message":"Could not resolve organisationService! Class organisationService does not exist","Code":0,"Trace":[{"file":"\/projects\/nextcloudserver\/lib\/private\/AppFramework\/Utility\/SimpleContainer.php","line":125,"function":"resolve","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["organisationService"]},{"file":"\/projects\/nextcloudserver\/lib\/private\/ServerContainer.php","line":132,"function":"query","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["organisationService"]},{"file":"\/projects\/nextcloudserver\/lib\/private\/AppFramework\/DependencyInjection\/DIContainer.php","line":427,"function":"query","class":"OC\\ServerContainer","type":"->","args":["organisationService"]},{"file":"\/projects\/nextcloudserver\/lib\/private\/AppFramework\/Utility\/SimpleContainer.php","line":81,"function":"query","class":"OC\\AppFramework\\DependencyInjection\\DIContainer","type":"->","args":["organisationService"]},{"file":"\/projects\/nextcloudserver\/lib\/private\/AppFramework\/Utility\/SimpleContainer.php","line":104,"function":"buildClass","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":[{"name":"OCA\\DocumentManager\\Controller\\OrganisationController","__class__":"ReflectionClass"}]},{"file":"\/projects\/nextcloudserver\/lib\/private\/AppFramework\/Utility\/SimpleContainer.php","line":125,"function":"resolve","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["OCA\\DocumentManager\\Controller\\OrganisationController"]},{"file":"\/projects\/nextcloudserver\/lib\/private\/AppFramework\/DependencyInjection\/DIContainer.php","line":453,"function":"query","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["OCA\\DocumentManager\\Controller\\OrganisationController"]},{"file":"\/projects\/nextcloudserver\/lib\/private\/AppFramework\/DependencyInjection\/DIContainer.php","line":424,"function":"queryNoFallback","class":"OC\\AppFramework\\DependencyInjection\\DIContainer","type":"->","args":["OCA\\DocumentManager\\Controller\\OrganisationController"]},{"file":"\/projects\/nextcloudserver\/lib\/private\/AppFramework\/App.php","line":105,"function":"query","class":"OC\\AppFramework\\DependencyInjection\\DIContainer","type":"->","args":["OCA\\DocumentManager\\Controller\\OrganisationController"]},{"file":"\/projects\/nextcloudserver\/lib\/private\/AppFramework\/Routing\/RouteActionHandler.php","line":47,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\DocumentManager\\Controller\\OrganisationController","index",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"_route":"documentmanager.organisation.index"}]},{"function":"__invoke","class":"OC\\AppFramework\\Routing\\RouteActionHandler","type":"->","args":[{"_route":"documentmanager.organisation.index"}]},{"file":"\/projects\/nextcloudserver\/lib\/private\/Route\/Router.php","line":297,"function":"call_user_func","args":[{"__class__":"OC\\AppFramework\\Routing\\RouteActionHandler"},{"_route":"documentmanager.organisation.index"}]},{"file":"\/projects\/nextcloudserver\/lib\/base.php","line":989,"function":"match","class":"OC\\Route\\Router","type":"->","args":["\/apps\/documentmanager\/organisations"]},{"file":"\/projects\/nextcloudserver\/index.php","line":42,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"\/projects\/nextcloudserver\/lib\/private\/AppFramework\/Utility\/SimpleContainer.php","Line":110,"CustomMessage":"--"},"userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/67.0.3396.99 Safari\/537.36","version":"14.0.0.10"}
{"reqId":"F4vRdpAOjDKpUB0zVj1f","level":3,"time":"2018-07-13T10:19:22+00:00","remoteAddr":"192.168.0.220","user":"admin","app":"PHP","method":"GET","url":"\/nextcloudserver\/index.php\/apps\/documentmanager\/organisations","message":"You are using a fallback implementation of the intl extension. Installing the native one is highly recommended instead. at \/projects\/nextcloudserver\/3rdparty\/patchwork\/utf8\/src\/Patchwork\/Utf8\/Bootup\/intl.php#18","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/67.0.3396.99 Safari\/537.36","version":"14.0.0.10"}

Browser log

Browser log
core.js?v=6616c648-0:7 JQMIGRATE: Migrate is installed, version 1.4.0
:33592/nextcloudserver/index.php/apps/documentmanager/organisations:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error)
angular.js:15018 Possibly unhandled rejection: {"data":"<!DOCTYPE html>\n<html class=\"ng-csp\" data-placeholder-focus=\"false\" lang=\"de-DE\" data-locale=\"en_US\" >\n\t<head data-requesttoken=\"\">\n\t\t<meta charset=\"utf-8\">\n\t\t<title>\n\t\tNextcloud\t\t</title>\n\t\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n\t\t<meta name=\"referrer\" content=\"no-referrer\">\n\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0\">\n\t\t<meta name=\"apple-itunes-app\" content=\"app-id=1125420102\">\n\t\t<meta name=\"theme-color\" content=\"#0082c9\">\n\t\t<link rel=\"icon\" href=\"/nextcloudserver/core/img/favicon.ico\">\n\t\t<link rel=\"apple-touch-icon-precomposed\" href=\"/nextcloudserver/core/img/favicon-touch.png\">\n\t\t<link rel=\"mask-icon\" sizes=\"any\" href=\"/nextcloudserver/core/img/favicon-mask.svg\" color=\"#0082c9\">\n\t\t<link rel=\"manifest\" href=\"/nextcloudserver/index.php/apps/theming/manifest?v=0\">\n\t\t<link rel=\"stylesheet\" href=\"/nextcloudserver/core/vendor/select2/select2.css?v=6616c648-0\">\n<link rel=\"stylesheet\" href=\"/nextcloudserver/core/vendor/jquery-ui/themes/base/jquery-ui.css?v=6616c648-0\">\n<link rel=\"stylesheet\" href=\"/nextcloudserver/apps/files_versions/css/versions.css?v=91a57076-0\">\n<link rel=\"stylesheet\" href=\"/nextcloudserver/core/css/guest.css?v=6616c648-0\">\n\t\t<script nonce=\"R0Y4cFBNQ0NlenUxMmxnMUUybWtmQzloa01lVDI1LzdOMlhIL1VGLzFyQT06VEdaa2FhWE9NVkxpdmlwTVJEN2xWMllFcDY3eHVldVpCd3ZzempJbW04RT0=\" defer src=\"/nextcloudserver/core/vendor/core.js?v=6616c648-0\"></script>\n<script nonce=\"R0Y4cFBNQ0NlenUxMmxnMUUybWtmQzloa01lVDI1LzdOMlhIL1VGLzFyQT06VEdaa2FhWE9NVkxpdmlwTVJEN2xWMllFcDY3eHVldVpCd3ZzempJbW04RT0=\" defer src=\"/nextcloudserver/index.php/js/core/merged-template-prepend.js?v=6616c648-0\"></script>\n<script nonce=\"R0Y4cFBNQ0NlenUxMmxnMUUybWtmQzloa01lVDI1LzdOMlhIL1VGLzFyQT06VEdaa2FhWE9NVkxpdmlwTVJEN2xWMllFcDY3eHVldVpCd3ZzempJbW04RT0=\" defer src=\"/nextcloudserver/core/search/js/search.js?v=6616c648-0\"></script>\n<script nonce=\"R0Y4cFBNQ0NlenUxMmxnMUUybWtmQzloa01lVDI1LzdOMlhIL1VGLzFyQT06VEdaa2FhWE9NVkxpdmlwTVJEN2xWMllFcDY3eHVldVpCd3ZzempJbW04RT0=\" defer src=\"/nextcloudserver/core/l10n/de_DE.js?v=6616c648-0\"></script>\n<script nonce=\"R0Y4cFBNQ0NlenUxMmxnMUUybWtmQzloa01lVDI1LzdOMlhIL1VGLzFyQT06VEdaa2FhWE9NVkxpdmlwTVJEN2xWMllFcDY3eHVldVpCd3ZzempJbW04RT0=\" defer src=\"/nextcloudserver/index.php/js/core/merged-share-backend.js?v=6616c648-0\"></script>\n<script nonce=\"R0Y4cFBNQ0NlenUxMmxnMUUybWtmQzloa01lVDI1LzdOMlhIL1VGLzFyQT06VEdaa2FhWE9NVkxpdmlwTVJEN2xWMllFcDY3eHVldVpCd3ZzempJbW04RT0=\" defer src=\"/nextcloudserver/core/search/js/searchprovider.js?v=6616c648-0\"></script>\n<script nonce=\"R0Y4cFBNQ0NlenUxMmxnMUUybWtmQzloa01lVDI1LzdOMlhIL1VGLzFyQT06VEdaa2FhWE9NVkxpdmlwTVJEN2xWMllFcDY3eHVldVpCd3ZzempJbW04RT0=\" defer src=\"/nextcloudserver/core/js/jquery-ui-fixes.js?v=6616c648-0\"></script>\n<script nonce=\"R0Y4cFBNQ0NlenUxMmxnMUUybWtmQzloa01lVDI1LzdOMlhIL1VGLzFyQT06VEdaa2FhWE9NVkxpdmlwTVJEN2xWMllFcDY3eHVldVpCd3ZzempJbW04RT0=\" defer src=\"/nextcloudserver/core/js/files/fileinfo.js?v=6616c648-0\"></script>\n<script nonce=\"R0Y4cFBNQ0NlenUxMmxnMUUybWtmQzloa01lVDI1LzdOMlhIL1VGLzFyQT06VEdaa2FhWE9NVkxpdmlwTVJEN2xWMllFcDY3eHVldVpCd3ZzempJbW04RT0=\" defer src=\"/nextcloudserver/core/js/files/client.js?v=6616c648-0\"></script>\n<script nonce=\"R0Y4cFBNQ0NlenUxMmxnMUUybWtmQzloa01lVDI1LzdOMlhIL1VGLzFyQT06VEdaa2FhWE9NVkxpdmlwTVJEN2xWMllFcDY3eHVldVpCd3ZzempJbW04RT0=\" defer src=\"/nextcloudserver/core/js/contactsmenu.js?v=6616c648-0\"></script>\n\t\t<link rel=\"stylesheet\" href=\"/nextcloudserver/index.php/apps/theming/styles?v=0\"/><script defer src=\"/nextcloudserver/index.php/apps/theming/js/theming?v=0\" nonce=\"R0Y4cFBNQ0NlenUxMmxnMUUybWtmQzloa01lVDI1LzdOMlhIL1VGLzFyQT06VEdaa2FhWE9NVkxpdmlwTVJEN2xWMllFcDY3eHVldVpCd3ZzempJbW04RT0=\"></script>\t</head>\n\t<body id=\"body-login\">\n\t\t<noscript>\n\t<div id=\"nojavascript\">\n\t\t<div>\n\t\t\tDiese Anwendung benötigt JavaScript zum ordnungsgemäßen Betrieb. Bitte <a href=\"https://www.enable-javascript.com/\" target=\"_blank\" rel=\"noreferrer noopener\">aktivieren Sie JavaScript</a> und laden Sie die Seite neu.\t\t</div>\n\t</div>\n</noscript>\n\t\t<div class=\"wrapper\">\n\t\t\t<div class=\"v-align\">\n\t\t\t\t\t\t\t\t\t<header role=\"banner\">\n\t\t\t\t\t\t<div id=\"header\">\n\t\t\t\t\t\t\t<div class=\"logo\">\n\t\t\t\t\t\t\t\t<h1 class=\"hidden-visually\">\n\t\t\t\t\t\t\t\t\tNextcloud\t\t\t\t\t\t\t\t</h1>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</header>\n\t\t\t\t\t\t\t\t<main>\n\t\t\t\t\t<div class=\"error error-wide\">\n\t<h2>Interner Serverfehler</h2>\n\t<p>Der Server konnte die Anfrage nicht fertig stellen.</p>\n\t<p>Sollte dies erneut auftreten, senden Sie bitte die nachfolgenden technischen Einzelheiten  an Ihren Server-Administrator.</p>\n\t<p>Weitere Details können im Server-Protokoll gefunden werden.</p>\n\n\t<h3>Technische Details</h3>\n\t<ul>\n\t\t<li>Entfernte Adresse: 192.168.0.220</li>\n\t\t<li>Anfragekennung: F4vRdpAOjDKpUB0zVj1f</li>\n\t\t\t</ul>\n\n\t</div>\n\t\t\t\t</main>\n\t\t\t</div>\n\t\t</div>\n\t\t<footer role=\"contentinfo\">\n\t\t\t<p class=\"info\">\n\t\t\t\t<a href=\"https://nextcloud.com\" target=\"_blank\" rel=\"noreferrer noopener\">Nextcloud</a> – ein sicherer Ort für all Ihre Daten\t\t\t</p>\n\t\t</footer>\n\t</body>\n</html>\n","status":500,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"/nextcloudserver/index.php/apps/documentmanager/organisations","headers":{"Accept":"application/json, text/plain, */*","requesttoken":"Mt5j18ywQI8Ho/jcHMj1XjvUbF7xslOxi6TLTndownY=:Zucugqn8CuZQx4qlS5+0dXKxWzeT0CfTu8rgfQQxjwc="}},"statusText":"Internal Server Error","xhrStatus":"complete"}
(anonymous) @ angular.js:15018

@nextcloud-bot
Copy link
Member

GitMate.io thinks possibly related issues are #2628 (Encryption migration failed (Class not Found)), #3636 (Update fails), #5043 (Class 'OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin' not found), #2737 (Updater fails to complete), and #10211 (Correctly init empty arrays).

@MorrisJobke
Copy link
Member

Do you have an example of the code that you use?

@DrRSatzteil
Copy link
Contributor Author

Yes I do. Please give me a couple of days though as I’m on holidays right now.

@DrRSatzteil
Copy link
Contributor Author

So back to work...

You can check out the app in:
https://github.com/DrRSatzteil/documentmanager/tree/issue10231

Note that it is by no means a complete app yet, I'm still learning... The class you are looking for is the OrganisationMapper that tries to load a list of organisations from the database upon startup. So just open the app and you should see the errors mentioned above.

@DrRSatzteil
Copy link
Contributor Author

Use "make all" to build after cloning

@DrRSatzteil
Copy link
Contributor Author

So I guess this issue can be closed. Could be reopened if there are classes part of the public interface that show the same behavior (I don’t know any though)

https://github.com/DrRSatzteil/documentmanager/commit/ce66e5c0b5e41177c5d46cf71b812f42c0ed80e6#commitcomment-29833295

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants