{"record":{"id":"1312b8a444ae1082","repo":"jeecgboot/JeecgBoot","slug":"error-1312b8","errorCode":null,"errorMessage":"退出租户失败，不存在此租户","messagePattern":"退出租户失败，不存在此租户","errorType":"exception","errorClass":"JeecgBootException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTenantServiceImpl.java","lineNumber":368,"sourceCode":"                throw new JeecgBootException(\"cancelTenant\");\n            } else {\n                throw new JeecgBootException(\"退出租户失败，租户信息已不存在\");\n            }\n        } else {\n            //不是拥有者直接删除\n            this.leaveTenant(userId, tenantId);\n            this.leveUserProcess(userId, tenantId);\n        }\n    }\n\n    @Override\n    public void changeOwenUserTenant(String userId, String tId) {\n        //查询当前用户是否存在该租户下\n        // 代码逻辑说明: 租户id应该是传过来的，不应该是当前租户的------------\n        int tenantId = oConvertUtils.getInt(tId, 0);\n        SysTenant sysTenant = tenantMapper.selectById(tenantId);\n        if(null == sysTenant){\n            throw new JeecgBootException(\"退出租户失败，不存在此租户\");\n        }\n        String createBy = sysTenant.getCreateBy();\n        Integer count = userTenantMapper.userTenantIzExist(userId, tenantId);\n        if (count == 0) {\n            throw new JeecgBootException(\"退出租户失败，此租户下没有该用户\");\n        }\n        //获取用户信息\n        SysUser user = userService.getById(userId);\n        //变更拥有者\n        SysTenant tenant = new SysTenant();\n        tenant.setCreateBy(user.getUsername());\n        tenant.setId(tenantId);\n        tenantMapper.updateById(tenant);\n        //删除当前登录用户的租户信息\n        //update-begin---author:wangshuai ---date:20230705  for：旧拥有者退出后，需要将就拥有者的用户租户关系改成已离职------------\n        //获取原创建人的用户id\n        SysUser userByName = userService.getUserByName(createBy);\n        LambdaQueryWrapper<SysUserTenant> query = new LambdaQueryWrapper<>();","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTenantServiceImpl.java#L350-L386","documentation":"changeOwenUserTenant throws when tenantMapper.selectById(tenantId) returns null — the tenant ID (parsed via oConvertUtils.getInt with default 0) does not correspond to any tenant row. Ownership cannot be transferred to a non-existent tenant.","triggerScenarios":"Calling changeOwenUserTenant(userId, tId) with a tenant ID that is missing, non-numeric (defaults to 0), or references a deleted tenant.","commonSituations":"Frontend passes a stale tenant id after the tenant was deleted; the tId param is undefined and parseInt yields 0; URL/query param naming mismatch so tId is blank; tenant was logically deleted but id still referenced in a link.","solutions":["Verify the tenantId is valid and the tenant row exists before calling changeOwenUserTenant.","Ensure the tId parameter is correctly bound from the request (check param name and that it is non-empty).","If the tenant was deleted, remove stale references in the UI/links that still point to it.","Add input validation to reject non-positive or non-numeric tenant IDs at the controller boundary."],"exampleFix":"// before\ntenantService.changeOwenUserTenant(userId, tId);\n\n// after\nint tenantId = oConvertUtils.getInt(tId, 0);\nif (tenantId <= 0 || tenantMapper.selectById(tenantId) == null) {\n    return Result.error(\"租户不存在，无法转让拥有者\");\n}\ntenantService.changeOwenUserTenant(userId, tId);","handlingStrategy":"validation","validationCode":"int tenantId = oConvertUtils.getInt(tId, 0);\nif (tenantId <= 0 || tenantMapper.selectById(tenantId) == null) {\n    return Result.error(\"租户不存在\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate tenantId is positive and exists at the controller boundary.","Ensure the tId request param is correctly named and bound.","Remove stale tenant references from UI links after deletion."],"tags":["tenant","validation","ownership","jeecg-boot"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}