{"record":{"id":"9e89752934b3b28f","repo":"elunez/eladmin","slug":"user-with-name-does-not-exist","errorCode":null,"errorMessage":"User with name {} does not exist","messagePattern":"User with name (.+?) does not exist","errorType":"exception","errorClass":"EntityNotFoundException","httpStatus":404,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java","lineNumber":178,"sourceCode":"        delCaches(user.getId(), user.getUsername());\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void delete(Set<Long> ids) {\n        for (Long id : ids) {\n            // 清理缓存\n            UserDto user = findById(id);\n            delCaches(user.getId(), user.getUsername());\n        }\n        userRepository.deleteAllByIdIn(ids);\n    }\n\n    @Override\n    public UserDto findByName(String userName) {\n        User user = userRepository.findByUsername(userName);\n        if (user == null) {\n            throw new EntityNotFoundException(User.class, \"name\", userName);\n        } else {\n            return userMapper.toDto(user);\n        }\n    }\n\n    @Override\n    public UserDto getLoginData(String userName) {\n        User user = userRepository.findByUsername(userName);\n        if (user == null) {\n            return null;\n        } else {\n            return userMapper.toDto(user);\n        }\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void updatePass(String username, String pass) {","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java#L160-L196","documentation":"EntityNotFoundException thrown in UserServiceImpl.findByName when no user row matches the username. Unlike getLoginData (which returns null for a missing user), findByName treats the absence as an error — it is the lookup used wherever a username is expected to exist.","triggerScenarios":"Any internal call resolving a username to a UserDto for a name with no row: e.g. processing data created by a user whose account was deleted, or a JWT whose subject no longer exists.","commonSituations":"Deleting users while their historical records (creator fields, comments, logs) still reference the name; stale tokens after user cleanup; renaming usernames without updating related references.","solutions":["Verify the username exists via the user management page or GET /api/users before referencing it.","Restore or re-create the missing account if history must keep resolving its creator.","Where 'missing' is legitimate, switch to getLoginData-style null handling instead of findByName."],"exampleFix":"// before: throws when user deleted\nUserDto u = userService.findByName(username);\n\n// after: handle absence explicitly\nUserDto u = userService.getLoginData(username);\nif (u == null) {\n    // treat as anonymous / skip / log\n}","handlingStrategy":"try-catch","validationCode":"User exists = userRepository.findByUsername(username);\nif (exists == null) { /* skip / anonymous / log */ return; }","typeGuard":null,"tryCatchPattern":"try { dto = userService.findByName(name); } catch (EntityNotFoundException e) { log.warn(\"user {} no longer exists\", name); dto = null; }","preventionTips":["Prefer getLoginData for optional lookups, findByName only when existence is guaranteed","Soft-delete or retain usernames referenced by history","Purge stale tokens/sessions when deleting users"],"tags":["eladmin","user","not-found","lookup","deleted-user"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}