{"record":{"id":"a6fdaae8a166fec4","repo":"theonedev/onedev","slug":"unknown-user-does-not-have-git-identity","errorCode":null,"errorMessage":"Unknown user does not have git identity","messagePattern":"Unknown user does not have git identity","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/model/User.java","lineNumber":776,"sourceCode":"\n\tpublic Collection<SsoAccount> getSsoAccounts() {\n\t\treturn ssoAccounts;\n\t}\n\n\tpublic void setSsoAccounts(Collection<SsoAccount> ssoAccounts) {\n\t\tthis.ssoAccounts = ssoAccounts;\n\t}\n\t\n\t@Override\n\tpublic String toString() {\n\t\treturn MoreObjects.toStringHelper(this)\n\t\t\t\t.add(\"name\", getName())\n\t\t\t\t.toString();\n\t}\n\t\n\tpublic PersonIdent asPerson() {\n\t\tif (isUnknown()) \n\t\t\tthrow new ExplicitException(\"Unknown user does not have git identity\");\n\t\telse if (isSystem())\n\t\t\treturn new PersonIdent(User.SYSTEM_NAME, getSystemNoreplyEmailAddress());\n\t\telse \n\t\t\treturn new PersonIdent(getDisplayName(), getGitEmailAddress().getValue());\t\t\n\t}\n\t\n\tpublic String getDisplayName() {\n\t\tif (getFullName() != null)\n\t\t\treturn getFullName();\n\t\telse\n\t\t\treturn getName();\n\t}\n\t\n\tpublic boolean isRoot() {\n\t\treturn ROOT_ID.equals(getId());\n\t}\n\n\tpublic boolean isSystem() {","sourceCodeStart":758,"sourceCodeEnd":794,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/model/User.java#L758-L794","documentation":"User.asPerson() converts a OneDev user into a JGit PersonIdent (git commit author/committer identity). The built-in 'Unknown' user represents unauthenticated/anonymous access and has no real name or email, so it cannot produce a git identity — calling asPerson() on it throws this ExplicitException.","triggerScenarios":"Calling user.asPerson() when user.isUnknown() is true — e.g. attempting to record a commit/push attribution for an anonymous or unresolved user identity.","commonSituations":"Code paths that attribute git operations before authentication is resolved; push hooks or scripts operating on the Unknown user; testing code that instantiates the unknown user and formats an identity.","solutions":["Ensure the operation runs with an authenticated user; resolve the actual User before calling asPerson()","Guard the call with if (!user.isUnknown()) and handle anonymous users explicitly (skip attribution or use a service account)","Use the system user (User.system) instead when an operation must be attributed but has no human actor"],"exampleFix":"// before\nPersonIdent ident = user.asPerson();\n// after\nif (user.isUnknown()) {\n    throw new IllegalStateException(\"Cannot attribute git operation to unknown user\");\n}\nPersonIdent ident = user.asPerson();","handlingStrategy":"type-guard","validationCode":"if (user == null || user.isUnknown()) throw new IllegalArgumentException(\"authenticated user required\");","typeGuard":"boolean hasGitIdentity(User u) { return u != null && !u.isUnknown(); }","tryCatchPattern":"try {\n    PersonIdent ident = user.asPerson();\n} catch (ExplicitException e) {\n    ident = new PersonIdent(User.SYSTEM_NAME, \"system@example.com\");\n}","preventionTips":["Resolve the acting user before git attribution","Never pass the Unknown user into commit/identity code paths","Use the system user for non-human operations"],"tags":["git","user","identity"],"backgroundTag":"invalid-state-transition","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}