{"record":{"id":"cd3906a8afffd3d1","repo":"halo-dev/halo","slug":"only-support-email-owner-kind","errorCode":null,"errorMessage":"Only support 'email' owner kind.","messagePattern":"Only support 'email' owner kind\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"application/src/main/java/run/halo/app/content/comment/OwnerInfo.java","lineNumber":43,"sourceCode":"\n    /** Owner display name. */\n    String displayName;\n\n    /** Owner avatar URL. */\n    String avatar;\n\n    /** Owner email address when available. */\n    String email;\n\n    /**\n     * Convert user to owner info by owner that has an email kind .\n     *\n     * @param owner comment owner reference.\n     * @return owner info.\n     */\n    public static OwnerInfo from(Comment.CommentOwner owner) {\n        if (!Comment.CommentOwner.KIND_EMAIL.equals(owner.getKind())) {\n            throw new IllegalArgumentException(\"Only support 'email' owner kind.\");\n        }\n        return OwnerInfo.builder()\n                .kind(owner.getKind())\n                .name(owner.getName())\n                .email(owner.getName())\n                .displayName(owner.getDisplayName())\n                .avatar(owner.getAnnotation(Comment.CommentOwner.AVATAR_ANNO))\n                .build();\n    }\n\n    /**\n     * Convert user to owner info by {@link User}.\n     *\n     * @param user user extension.\n     * @return owner info.\n     */\n    public static OwnerInfo from(User user) {\n        return OwnerInfo.builder()","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/halo-dev/halo/blob/d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8/application/src/main/java/run/halo/app/content/comment/OwnerInfo.java#L25-L61","documentation":"OwnerInfo.from(Comment.CommentOwner) converts a comment owner reference into an OwnerInfo, but only supports owners whose kind equals Comment.CommentOwner.KIND_EMAIL. It throws IllegalArgumentException for any other owner kind (e.g. a user or a custom owner kind registered by a plugin).","triggerScenarios":"Calling OwnerInfo.from(owner) where owner.getKind() returns something other than the EMAIL kind constant — e.g. KIND_USER, a plugin-defined owner kind, or null.","commonSituations":"A plugin introduces a new comment owner kind and reuses OwnerInfo.from to render it; mixing user-authenticated comment owners with anonymous email owners in a code path that assumes email only.","solutions":["Guard the call: check Comment.CommentOwner.KIND_EMAIL.equals(owner.getKind()) before invoking from().","For non-email owners, build OwnerInfo via its builder or the User-based overload instead.","If you are a plugin adding a new owner kind, do not route it through from(owner); provide your own mapping."],"exampleFix":"// before\nvar info = OwnerInfo.from(owner); // throws when owner is a user\n\n// after\nvar info = Comment.CommentOwner.KIND_EMAIL.equals(owner.getKind())\n    ? OwnerInfo.from(owner)\n    : OwnerInfo.builder().kind(owner.getKind()).name(owner.getName()).build();","handlingStrategy":"type-guard","validationCode":"if (!Comment.CommentOwner.KIND_EMAIL.equals(owner.getKind())) {\n    // build OwnerInfo another way (User overload / builder); do not call from(owner)\n}","typeGuard":"static boolean isEmailOwner(Comment.CommentOwner owner) {\n    return owner != null\n        && Comment.CommentOwner.KIND_EMAIL.equals(owner.getKind());\n}","tryCatchPattern":null,"preventionTips":["Always check owner.getKind() against KIND_EMAIL before calling OwnerInfo.from(owner).","For user/plugin owner kinds, use the User-based overload or the builder.","Do not assume all comment owners are email-kind when porting code from an email-only flow."],"tags":["validation","comment","owner-kind","precondition"],"backgroundTag":null,"analyzedSha":"d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8","analyzedAt":"2026-08-14T00:18:38.915Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}