{"record":{"id":"189ebddd976be6d9","repo":"apolloconfig/apollo","slug":"favorite-not-exist","errorCode":null,"errorMessage":"favorite not exist","messagePattern":"favorite not exist","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/FavoriteService.java","lineNumber":128,"sourceCode":"\n  public void adjustFavoriteToFirst(long favoriteId, String loginUserId) {\n    Favorite favorite = favoriteRepository.findById(favoriteId).orElse(null);\n\n    checkUserOperatePermission(favorite, loginUserId);\n\n    String userId = favorite.getUserId();\n    Favorite firstFavorite =\n        favoriteRepository.findFirstByUserIdOrderByPositionAscDataChangeCreatedTimeAsc(userId);\n    long minPosition = firstFavorite.getPosition();\n\n    favorite.setPosition(minPosition - 1);\n\n    favoriteRepository.save(favorite);\n  }\n\n  private void checkUserOperatePermission(Favorite favorite, String loginUserId) {\n    if (favorite == null) {\n      throw new BadRequestException(\"favorite not exist\");\n    }\n\n    if (!Objects.equals(loginUserId, favorite.getUserId())) {\n      throw new BadRequestException(\"can not operate other person's favorite\");\n    }\n  }\n\n  public void batchDeleteByAppId(String appId, String operator) {\n    favoriteRepository.batchDeleteByAppId(appId, operator);\n  }\n}\n","sourceCodeStart":110,"sourceCodeEnd":140,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/FavoriteService.java#L110-L140","documentation":"Thrown as a BadRequestException by FavoriteService.checkUserOperatePermission() when the favorite parameter is null. This private method guards update/delete/adjust-position operations. A null favorite means the referenced favorite ID was not found by the repository before the permission check, indicating the favorite doesn't exist.","triggerScenarios":"Calling any operation that invokes checkUserOperatePermission (adjustFavoriteToFirst, delete, etc.) with a favorite ID that the repository cannot find, resulting in a null Favorite passed to the permission check.","commonSituations":"Attempting to delete or reorder a favorite that was already removed; stale client-side cache referencing a deleted favorite; favorite ID typo; concurrent deletion by another session or admin cleanup.","solutions":["Verify the favorite ID exists before attempting to operate on it by calling the favorite query API.","Handle a 'not found' response gracefully in the UI by refreshing the favorites list.","Check if the favorite was deleted by another session or an admin batch delete (batchDeleteByAppId).","Ensure the client does not cache stale favorite IDs across sessions."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Check favorite exists before operating\nFavorite favorite = favoriteRepository.findById(favoriteId).orElse(null);\nif (favorite == null) {\n  // handle gracefully - refresh list, inform user\n  throw new IllegalArgumentException(\"Favorite not found: \" + favoriteId);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify the favorite ID exists before performing delete or reorder operations.","Refresh the favorites list in the UI if a not-found error occurs.","Avoid caching favorite IDs across sessions as they may be deleted."],"tags":["apollo-portal","favorite","bad-request","not-found","permission"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}