{"record":{"id":"d71377dddeaddea1","repo":"alibaba/ARouter","slug":"init-provider-failed-provider-name-reason","errorCode":null,"errorMessage":"Init provider failed! provider = [<name>], reason = [<failure>]","messagePattern":"Init provider failed! provider = \\[<name>\\], reason = \\[<failure>\\]","errorType":"exception","errorClass":"HandlerException","httpStatus":null,"severity":"error","filePath":"arouter-api/src/main/java/com/alibaba/android/arouter/core/LogisticsCenter.java","lineNumber":345,"sourceCode":"                // Save raw uri\n                postcard.withString(ARouter.RAW_URI, rawUri.toString());\n            }\n\n            switch (routeMeta.getType()) {\n                case PROVIDER:  // if the route is provider, should find its instance\n                    // Its provider, so it must implement IProvider\n                    Class<? extends IProvider> providerMeta = (Class<? extends IProvider>) routeMeta.getDestination();\n                    IProvider instance = Warehouse.providers.get(providerMeta);\n                    if (null == instance) { // There's no instance of this provider\n                        IProvider provider;\n                        try {\n                            provider = providerMeta.getConstructor().newInstance();\n                            provider.init(mContext);\n                            Warehouse.providers.put(providerMeta, provider);\n                            instance = provider;\n                        } catch (Exception e) {\n                            logger.error(TAG, \"Init provider failed!\", e);\n                            throw new HandlerException(\n                                    \"Init provider failed! provider = [\" + providerMeta.getName()\n                                            + \"], reason = [\" + describeFailure(e) + \"]\",\n                                    e\n                            );\n                        }\n                    }\n                    postcard.setProvider(instance);\n                    postcard.greenChannel();    // Provider should skip all of interceptors\n                    break;\n                case FRAGMENT:\n                    postcard.greenChannel();    // Fragment needn't interceptors\n                default:\n                    break;\n            }\n        }\n    }\n\n    /**","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/alibaba/ARouter/blob/84f451d244e3fb1d0e37801de1b9ee2af2f81d68/arouter-api/src/main/java/com/alibaba/android/arouter/core/LogisticsCenter.java#L327-L363","documentation":"completion() instantiates an IProvider for a route/provider meta, calls its init(context), and registers it in Warehouse. If construction, init, or registration throws, it logs 'Init provider failed!' and wraps the cause in HandlerException naming the provider class and failure reason.","triggerScenarios":"Provider class has no public no-arg constructor (newInstance fails), its init() throws (e.g. missing API key, unmet service dependency), or Warehouse.providers registration fails; triggered on first navigation/service-fetch requiring that provider.","commonSituations":"Provider's init reads a missing config/env value; provider constructor does implicit dependency lookup that isn't ready; obfuscation renamed the class so reflective lookup breaks; provider incompatible with the current arouter-api version.","solutions":["Read reason = [<failure>] and fix the exception thrown inside the provider's init()/constructor","Ensure the provider class is public with a public no-arg constructor","Guard provider init against missing configuration: validate required keys before init and fail early with a clear message","Add keep rules so R8 doesn't break reflective instantiation: -keep class * implements com.alibaba.android.arouter.facade.template.IProvider { *; }"],"exampleFix":"// before\npublic class PayProvider implements IProvider {\n    public PayProvider( Context c ) {...} // no default ctor\n    @Override public void init(Context ctx) { key = Config.KEY; } // NPE if missing\n}\n// after\npublic class PayProvider implements IProvider {\n    public PayProvider() {}\n    @Override public void init(Context ctx) {\n        String key = Config.get(\"pay.key\");\n        if (key == null || key.isEmpty()) {\n            throw new IllegalStateException(\"pay.key not configured\"); // surfaces clearly in reason\n        }\n        this.key = key;\n    }\n}","handlingStrategy":"try-catch","validationCode":"// preflight provider requirements before triggering it via navigation\nif (TextUtils.isEmpty(Config.get(\"pay.key\"))) {\n    Log.e(TAG, \"pay.key missing; PayProvider init will fail\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    IPayService pay = ARouter.getInstance().navigation(IPayService.class);\n    pay.pay(order);\n} catch (HandlerException e) {\n    Log.e(TAG, \"provider init failed: \" + e.getMessage(), e.getCause());\n    // degrade feature or surface config error\n}","preventionTips":["Validate all config the provider's init() needs before first navigation","Always provide a public no-arg constructor on IProvider implementations","Keep IProvider classes from R8 obfuscation","Fail fast in init() with descriptive messages so reason=[...] is actionable"],"tags":["arouter","provider","reflection","initialization"],"backgroundTag":"module-init-failed","analyzedSha":"84f451d244e3fb1d0e37801de1b9ee2af2f81d68","analyzedAt":"2026-09-06T13:30:41.084Z","contentChangedAt":"2026-09-06T13:30:41.084Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}