{"record":{"id":"2379763c4a374a7a","repo":"apache/dolphinscheduler","slug":"java-lang-clonenotsupportedexception","errorCode":null,"errorMessage":"java.lang.CloneNotSupportedException","messagePattern":"java\\.lang\\.CloneNotSupportedException","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/FavTaskServiceImpl.java","lineNumber":58,"sourceCode":"    @Resource\n    private FavTaskMapper favMapper;\n\n    @Override\n    public List<FavTaskDto> getFavTaskList(User loginUser) {\n        Set<String> userFavTaskTypes = favMapper.getUserFavTaskTypes(loginUser.getId());\n\n        List<FavTaskDto> defaultTaskTypes = taskTypeConfiguration.getDefaultTaskTypes();\n        List<FavTaskDto> result = new ArrayList<>();\n        // clone default list and modify fav task type flag\n        defaultTaskTypes.forEach(e -> {\n            try {\n                FavTaskDto clone = (FavTaskDto) e.clone();\n                if (userFavTaskTypes.contains(clone.getTaskType())) {\n                    clone.setCollection(true);\n                }\n                result.add(clone);\n            } catch (CloneNotSupportedException ex) {\n                throw new RuntimeException(ex);\n            }\n        });\n        return result;\n    }\n\n    @Override\n    public boolean deleteFavTask(User loginUser, String taskType) {\n        return favMapper.deleteUserFavTask(loginUser.getId(), taskType);\n    }\n\n    @Override\n    public int addFavTask(User loginUser, String taskType) {\n        favMapper.deleteUserFavTask(loginUser.getId(), taskType);\n        return favMapper.insert(new FavTask(null, taskType, loginUser.getId()));\n    }\n}\n","sourceCodeStart":40,"sourceCodeEnd":75,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/FavTaskServiceImpl.java#L40-L75","documentation":"getFavTaskList clones FavTaskDto instances via e.clone(), and if the clone operation raises CloneNotSupportedException the code wraps it in a RuntimeException, surfacing as 'java.lang.CloneNotSupportedException'. This happens when FavTaskDto does not properly implement Cloneable, so Object.clone() refuses to copy it.","triggerScenarios":"Calling getFavTaskList when FavTaskDto (or the element being cloned) fails to implement java.lang.Cloneable — Object.clone() throws and the catch block rethrows it as RuntimeException.","commonSituations":"Refactoring FavTaskDto (e.g. removing Cloneable or changing hierarchy) breaks clone-based copying; running a build where the DTO was modified without re-checking the clone contract.","solutions":["Make FavTaskDto implement Cloneable (and keep super.clone()), or better, replace the clone() call with a copy constructor / explicit field copy.","Fix the DTO class in the source tree; this is a code defect, not a runtime configuration issue.","Upgrade to a version where the clone usage is removed."],"exampleFix":"// before\nFavTaskDto clone = (FavTaskDto) e.clone();\n// after (copy constructor)\nFavTaskDto clone = new FavTaskDto(e);\nclone.setCollection(userFavTaskTypes.contains(clone.getTaskType()));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return getFavTaskList(loginUser); } catch (RuntimeException e) { if (e.getCause() instanceof CloneNotSupportedException) { /* rebuild fav list without clone, or report DTO defect */ } else throw e; }","preventionTips":["Ensure DTOs used with clone() implement Cloneable.","Prefer copy constructors or deep-copy helpers over Object.clone().","Add unit tests covering getFavTaskList after DTO changes."],"tags":["clone","java","runtime-exception","dolphinscheduler"],"backgroundTag":"internal-invariant-violation","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}