{"record":{"id":"3b46abbc18a7db55","repo":"alibaba/COLA","slug":"companyname-has-already-existed-you-can-not-ad","errorCode":null,"errorMessage":"${companyName} has already existed, you can not add it","messagePattern":"(.+?) has already existed, you can not add it","errorType":"exception","errorClass":"BizException","httpStatus":null,"severity":"warning","filePath":"cola-archetypes/cola-archetype-service/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/Customer.java","lineNumber":37,"sourceCode":"    private String companyName;\n    private SourceType sourceType;\n    private CompanyType companyType;\n\n    public Customer() {\n    }\n\n    public boolean isBigCompany() {\n        return registeredCapital > 10000000; //注册资金大于1000万的是大企业\n    }\n\n    public boolean isSME() {\n        return registeredCapital > 10000 && registeredCapital < 1000000; //注册资金大于10万小于100万的为中小企业\n    }\n\n    public void checkConflict(){\n        //Per different biz, the check policy could be different, if so, use ExtensionPoint\n        if(\"ConflictCompanyName\".equals(this.companyName)){\n            throw new BizException(this.companyName+\" has already existed, you can not add it\");\n        }\n\n    }\n}\n","sourceCodeStart":19,"sourceCodeEnd":42,"githubUrl":"https://github.com/alibaba/COLA/blob/352e1a867538d9cd40e1b11e4028fa652fc97557/cola-archetypes/cola-archetype-service/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/Customer.java#L19-L42","documentation":"Customer.checkConflict() is a domain method enforcing that a customer's company name does not collide with an existing one; in the archetype it throws BizException when companyName equals the sentinel \"ConflictCompanyName\". The message embeds the actual conflicting company name.","triggerScenarios":"Calling customer.checkConflict() (typically from a creation use case) when this.customerName/companyName equals \"ConflictCompanyName\".","commonSituations":"Demo/test data using the sentinel name; developers copying this domain entity and forgetting to replace the literal with a real duplicate check (e.g. repository lookup or ExtensionPoint policy).","solutions":["Use a different companyName value in the request.","Replace the hard-coded string comparison with a real conflict policy (repository existence check or per-biz ExtensionPoint).","Catch BizException from checkConflict() at the executor level and map it to a proper error response."],"exampleFix":"// before\nif(\"ConflictCompanyName\".equals(this.companyName)){\n    throw new BizException(this.companyName+\" has already existed, you can not add it\");\n}\n// after\nif(customerRepository.existsByCompanyName(this.companyName)){\n    throw new BizException(this.companyName+\" has already existed, you can not add it\");\n}","handlingStrategy":"validation","validationCode":"if (!\"ConflictCompanyName\".equals(customer.getCompanyName())) {\n    customer.checkConflict();\n} else {\n    return Response.buildFailure(\"CUSTOMER_CONFLICT\", customer.getCompanyName() + \" has already existed\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    customer.checkConflict();\n} catch (BizException e) {\n    return Response.buildFailure(ErrorCode.B_CUSTOMER_companyNameConflict.getErrCode(), e.getMessage());\n}","preventionTips":["Validate company name uniqueness at the application layer before calling domain checkConflict().","Replace the literal sentinel with a repository-backed existence check or ExtensionPoint policy.","Centralize conflict handling in the executor so the domain exception never reaches raw clients."],"tags":["domain-model","uniqueness-conflict","cola"],"backgroundTag":"schema-validation-failed","analyzedSha":"352e1a867538d9cd40e1b11e4028fa652fc97557","analyzedAt":"2026-09-08T00:46:23.972Z","contentChangedAt":"2026-09-08T00:46:23.972Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}