{"record":{"id":"856aa515ef1bded6","repo":"alibaba/ARouter","slug":"extract-the-default-group-failed-the-path-must-be","errorCode":null,"errorMessage":"Extract the default group failed, the path must be start with '/' and contain more than 2 '/'!","messagePattern":"Extract the default group failed, the path must be start with '/' and contain more than 2 '/'!","errorType":"exception","errorClass":"HandlerException","httpStatus":null,"severity":"error","filePath":"arouter-api/src/main/java/com/alibaba/android/arouter/launcher/_ARouter.java","lineNumber":245,"sourceCode":"     * Check route availability without navigating to the destination.\n     */\n    protected boolean hasRoute(String path) {\n        final Postcard postcard;\n        try {\n            postcard = build(path);\n        } catch (HandlerException invalidPath) {\n            return false;\n        }\n\n        return LogisticsCenter.hasRoute(postcard);\n    }\n\n    /**\n     * Extract the default group from path.\n     */\n    private String extractGroup(String path) {\n        if (TextUtils.isEmpty(path) || !path.startsWith(\"/\")) {\n            throw new HandlerException(Consts.TAG + \"Extract the default group failed, the path must be start with '/' and contain more than 2 '/'!\");\n        }\n\n        try {\n            String defaultGroup = path.substring(1, path.indexOf(\"/\", 1));\n            if (TextUtils.isEmpty(defaultGroup)) {\n                throw new HandlerException(Consts.TAG + \"Extract the default group failed! There's nothing between 2 '/'!\");\n            } else {\n                return defaultGroup;\n            }\n        } catch (Exception e) {\n            logger.warning(Consts.TAG, \"Failed to extract default group! \" + e.getMessage());\n            return null;\n        }\n    }\n\n    static void afterInit() {\n        // Trigger interceptor init, use byName.\n        interceptorService = (InterceptorService) ARouter.getInstance().build(\"/arouter/service/interceptor\").navigation();","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/alibaba/ARouter/blob/84f451d244e3fb1d0e37801de1b9ee2af2f81d68/arouter-api/src/main/java/com/alibaba/android/arouter/launcher/_ARouter.java#L227-L263","documentation":"extractGroup derives the route group (the segment between the first and second '/') from a path. ARouter throws HandlerException when the path is empty or does not start with '/', because the documented path convention '/group/xxx' cannot be parsed.","triggerScenarios":"Calling build(\"user/login\") (missing leading slash), build(\"\"), or hasRoute with such a path; passing a full URI string ('http://...') where a path is expected.","commonSituations":"Routes stored without the leading slash in config files; users passing package/class names instead of route paths; paths generated by concatenation losing the '/'; deep-link URL host+path mixed up.","solutions":["Ensure every route path starts with '/' and contains at least two slashes: '/group/path'","Normalize external input before building, e.g. prepend '/' when missing","Register routes with the same convention used at lookup time","Prefer the two-segment form and validate with a regex ^/[A-Za-z0-9_]+/.+"],"exampleFix":"// before\nARouter.getInstance().build(\"user/login\").navigation(); // HandlerException\n// after\nString path = \"user/login\";\nif (!path.startsWith(\"/\")) path = \"/\" + path;\nARouter.getInstance().build(path).navigation();","handlingStrategy":"validation","validationCode":"private static final Pattern ROUTE = Pattern.compile(\"^/[A-Za-z0-9_]+/.+\");\npublic static boolean isValidRoutePath(String p) {\n    return p != null && ROUTE.matcher(p).matches();\n}","typeGuard":null,"tryCatchPattern":"try {\n    ARouter.getInstance().build(path).navigation();\n} catch (HandlerException e) {\n    Log.w(TAG, \"Path must look like /group/xxx\", e);\n}","preventionTips":["Enforce the '/group/segment' convention in code review and CI","Normalize external inputs to add the leading slash","Store route constants centrally with the full two-segment path"],"tags":["android","arouter","path-format","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"84f451d244e3fb1d0e37801de1b9ee2af2f81d68","analyzedAt":"2026-09-06T13:30:41.084Z","contentChangedAt":"2026-09-06T13:30:41.084Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}