{"record":{"id":"875d1d3ae01af9ea","repo":"SonarSource/sonarqube","slug":"unknown-branch-type-s","errorCode":null,"errorMessage":"Unknown branch type '%s'","messagePattern":"Unknown branch type '(.+?)'","errorType":"exception","errorClass":"IllegalStateException","httpStatus":500,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java","lineNumber":162,"sourceCode":"    }\n    builder.setComponentKey(componentDto.getKey());\n    builder.setComponentName(componentDto.name());\n    builder.setComponentQualifier(componentDto.qualifier());\n    return builder;\n  }\n\n  private static Ce.Task.Builder setBranchOrPullRequest(Ce.Task.Builder builder, String taskUuid, DtoCache componentDtoCache) {\n    componentDtoCache.getBranchKey(taskUuid).ifPresent(\n      b -> {\n        Common.BranchType branchType = componentDtoCache.getBranchType(taskUuid)\n          .orElseThrow(() -> new IllegalStateException(format(\"Could not find branch type of task '%s'\", taskUuid)));\n        switch (branchType) {\n          case BRANCH:\n            builder.setBranchType(branchType);\n            builder.setBranch(b);\n            break;\n          default:\n            throw new IllegalStateException(String.format(\"Unknown branch type '%s'\", branchType));\n        }\n      });\n    componentDtoCache.getPullRequest(taskUuid).ifPresent(builder::setPullRequest);\n    return builder;\n  }\n\n  private static List<String> extractWarningMessages(CeActivityDto dto) {\n    return dto.getCeTaskMessageDtos().stream()\n      .filter(ceTaskMessageDto -> ceTaskMessageDto.getType().isWarning())\n      .map(CeTaskMessageDto::getMessage)\n      .toList();\n  }\n\n  private static List<String> extractInfoMessages(CeActivityDto activityDto) {\n    return activityDto.getCeTaskMessageDtos().stream()\n      .filter(ceTaskMessageDto -> MessageType.INFO.equals(ceTaskMessageDto.getType()))\n      .sorted(Comparator.comparing(CeTaskMessageDto::getCreatedAt))\n      .map(CeTaskMessageDto::getMessage)","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java#L144-L180","documentation":"TaskFormatter.formatQueue/formatActivity build task representations and attach branch metadata via setBranchOrPullRequest. The task's branchType field must be BRANCH; any other value (e.g. PULL_REQUEST flowing through the branch path, or a corrupted/null-ish value) hits the default case and throws this IllegalStateException. It signals an internal inconsistency in how CE task branch data was stored or selected.","triggerScenarios":"A queued/activity CE task whose branchType is anything other than the BRANCH constant while setBranchOrPullRequest iterates it — e.g. a pull-request task wrongly surfaced in the branch lookup, or a DB row with an unexpected branch_type value.","commonSituations":"Plugin or DB migration wrote an unexpected branch_type; calling the api/ce/activity or api/ce/task endpoints for tasks where branch and pull request data are inconsistent; upgrading SonarQube with stale ce_activity rows.","solutions":["Check the ce_activity/branch rows backing the failing task UUID and correct branch_type to 'BRANCH'","Verify the task is a branch task, not a pull-request task — PR tasks are resolved via componentDtoCache.getPullRequest and never enter this switch","Clear stale task data via api/ce/clear or purge the task row and re-run analysis","Upgrade to a SonarQube version where the formatter fix matches your DB schema"],"exampleFix":"// before\ndefault:\n  throw new IllegalStateException(String.format(\"Unknown branch type '%s'\", branchType));\n// after\ncase PULL_REQUEST:\n  builder.setBranchType(branchType);\n  break;\ndefault:\n  LOGGER.warn(\"Skipping unknown branch type '{}' for task {}\", branchType, taskUuid);","handlingStrategy":"try-catch","validationCode":"// Java: check before calling the formatter for a task\nBranchDto branch = branchDao.selectByUuid(dbSession, task.getBranchUuid()).orElse(null);\nif (branch == null || !\"BRANCH\".equals(branch.getBranchType())) {\n    throw new IllegalArgumentException(\"task is not a branch task: \" + task.getUuid());\n}","typeGuard":"boolean isBranchTask(TaskDto t) {\n  return \"BRANCH\".equals(t.getBranchType());\n}","tryCatchPattern":"try {\n  TaskFormatterMessage msg = formatter.format(task);\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Unknown branch type\")) {\n    LOGGER.warn(\"Skipping task {} with unknown branch type\", task.getUuid());\n  } else { throw e; }\n}","preventionTips":["Treat PR tasks and branch tasks as distinct types and route them before formatting","Validate branch_type values when migrating or copying ce_activity rows","Add integration tests covering tasks for branches and pull requests","Keep SonarQube version and DB schema in sync during upgrades"],"tags":["java","ce-webservices","internal-state"],"backgroundTag":"invalid-enum-value","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}