{"record":{"id":"6957f3f79e8d819d","repo":"apereo/cas","slug":"cannot-update-a-resource-set-with-inconsistent-mis","errorCode":null,"errorMessage":"Cannot update a resource set with inconsistent/mismatched identifiers.","messagePattern":"Cannot update a resource set with inconsistent/mismatched identifiers\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"support/cas-server-support-oauth-uma-core/src/main/java/org/apereo/cas/uma/ticket/resource/repository/BaseResourceSetRepository.java","lineNumber":44,"sourceCode":"    public long count() {\n        return getAll().size();\n    }\n\n    @Override\n    public ResourceSet save(final ResourceSet set) {\n        if (!validateResourceSetScopes(set)) {\n            throw new IllegalArgumentException(\"Cannot save a resource set with inconsistent scopes.\");\n        }\n        return saveInternal(set);\n    }\n\n    @Override\n    public ResourceSet update(final ResourceSet currentResource, final ResourceSet newResource) {\n        if (currentResource.getId() <= 0 || newResource.getId() <= 0) {\n            throw new IllegalArgumentException(\"Cannot update a resource set without identifiers.\");\n        }\n        if (currentResource.getId() != newResource.getId()) {\n            throw new IllegalArgumentException(\"Cannot update a resource set with inconsistent/mismatched identifiers.\");\n        }\n        if (!validateResourceSetScopes(newResource)) {\n            throw new IllegalArgumentException(\"Cannot save a resource set with inconsistent scopes.\");\n        }\n\n        currentResource.setOwner(newResource.getOwner());\n        currentResource.setClientId(newResource.getClientId());\n        currentResource.setName(newResource.getName());\n        currentResource.setIconUri(newResource.getIconUri());\n        currentResource.setPolicies(newResource.getPolicies());\n        currentResource.setScopes(newResource.getScopes());\n        currentResource.setType(newResource.getType());\n        currentResource.setUri(newResource.getUri());\n\n        return saveInternal(currentResource);\n    }\n\n    /**","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/support/cas-server-support-oauth-uma-core/src/main/java/org/apereo/cas/uma/ticket/resource/repository/BaseResourceSetRepository.java#L26-L62","documentation":"Thrown by BaseResourceSetRepository.update when currentResource.getId() and newResource.getId() differ. The update operation treats the two objects as two versions of the same resource set, so mismatched ids would silently overwrite the wrong entity. CAS rejects this as an invariant violation.","triggerScenarios":"Calling update(current, new) where the two ResourceSets represent different resource sets, e.g. mixing up objects from two requests or copying fields from another resource set.","commonSituations":"Batch-processing resource sets and pairing the wrong current/new objects; deserializing client payloads where _id was changed by the client; stale objects after a re-save assigned a new id.","solutions":["Ensure newResource is a copy of currentResource (same id) with only the fields you want changed.","Verify the client's _id matches the resource set being updated before applying changes.","If ids genuinely differ, delete the old resource set and save the new one instead of update().","Catch IllegalArgumentException and return a 404/400 mismatched-id error to the caller."],"exampleFix":"// before\nResourceSet other = repository.getAll().get(3);\nrepository.update(current, other); // ids differ -> throws\n// after\nResourceSet updated = repository.findResourceSetById(current.getId()).get();\nupdated.setName(\"new-name\");\nrepository.update(current, updated);","handlingStrategy":"validation","validationCode":"if (current.getId() != updated.getId()) {\n    throw new IllegalStateException(\"ResourceSet id mismatch: \" + current.getId() + \" vs \" + updated.getId());\n}","typeGuard":null,"tryCatchPattern":"try { repository.update(current, updated); } catch (IllegalArgumentException e) {\n    return ResponseEntity.status(404).body(Map.of(\"error\", \"mismatched_resource_set_id\"));\n}","preventionTips":["Clone the loaded entity and mutate fields rather than pairing unrelated objects","Ignore client-supplied id changes; key updates on the URL/resource id","Log id pairs in update flows for easier diagnosis"],"tags":["uma","oauth","resource-set","id-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"e7288fc434b4f4505b8452e1a57e8fb3111bb863","analyzedAt":"2026-09-08T15:39:16.015Z","contentChangedAt":"2026-09-08T15:39:16.015Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}