{"record":{"id":"e6ac4351afd9799e","repo":"gradle/gradle","slug":"problem-id-parent-must-not-be-null","errorCode":null,"errorMessage":"Problem id parent must not be null","messagePattern":"Problem id parent must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"platforms/ide/problems-api/src/main/java/org/gradle/api/problems/internal/DefaultProblemId.java","lineNumber":48,"sourceCode":"    private final String displayName;\n    private final ProblemGroup parent;\n\n    public DefaultProblemId(String name, String displayName, ProblemGroup parent) {\n        validateFields(name, displayName, parent);\n        this.name = TextUtil.replaceLineSeparatorsOf(name, \"\");\n        this.displayName = TextUtil.replaceLineSeparatorsOf(displayName, \"\");\n        this.parent = parent;\n    }\n\n    private static void validateFields(String name, String displayName, ProblemGroup parent) {\n        if (TextUtil.isBlank(name)) {\n            throw new IllegalArgumentException(\"Problem id name must not be blank\");\n        }\n        if (TextUtil.isBlank(displayName)) {\n            throw new IllegalArgumentException(\"Problem id displayName must not be blank\");\n        }\n        if (parent == null) {\n            throw new IllegalArgumentException(\"Problem id parent must not be null\");\n        }\n    }\n\n    @Override\n    public String getName() {\n        return name;\n    }\n\n    @Override\n    public String getDisplayName() {\n        return displayName;\n    }\n\n    @Override\n    public ProblemGroup getGroup() {\n        return parent;\n    }\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/gradle/gradle/blob/534f27719b66953f95cc907aae7f2c1b12f5482d/platforms/ide/problems-api/src/main/java/org/gradle/api/problems/internal/DefaultProblemId.java#L30-L66","documentation":"DefaultProblemId's constructor requires a non-null parent ProblemGroup; every problem ID belongs to a group (the group provides context and grouping in reports). A null parent leaves the ID unattached, so validateFields throws IllegalArgumentException('Problem id parent must not be null').","triggerScenarios":"Constructing new DefaultProblemId(\"name\", \"displayName\", null); passing a group variable that was never assigned; a factory method that forgets the group argument.","commonSituations":"Copy-pasted ID construction with the group parameter dropped; group lookup (e.g. from a registry) returning null for an unknown key; older code migrated from APIs where parent was optional.","solutions":["Pass an existing ProblemGroup, e.g. new DefaultProblemId('name', 'display', new DefaultProblemGroup('group', 'Group display'))","If the group is looked up, fail with a clear message when the lookup returns null instead of passing null through","Use the public problems API where groups are created and attached for you"],"exampleFix":"// before\nProblemId id = new DefaultProblemId(\"parse-error\", \"Parse error\", findGroup(groupId)); // returns null -> throws\n\n// after\nProblemGroup group = findGroup(groupId);\nif (group == null) throw new IllegalArgumentException(\"Unknown problem group: \" + groupId);\nProblemId id = new DefaultProblemId(\"parse-error\", \"Parse error\", group);","handlingStrategy":"validation","validationCode":"// Java: null-check the parent before constructing\nProblemGroup group = findGroup(groupId);\nif (group == null) {\n    throw new IllegalArgumentException(\"Unknown problem group id: \" + groupId);\n}\nProblemId id = new DefaultProblemId(\"name\", \"display\", group);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve the parent group first and fail with its identifier if missing","Create the group before the ID in registration code","Avoid APIs where the parent is optional in your own wrappers"],"tags":["problems-api","gradle","validation","null-parent","plugin-development"],"backgroundTag":"required-property-null","analyzedSha":"534f27719b66953f95cc907aae7f2c1b12f5482d","analyzedAt":"2026-08-22T08:09:12.375Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}