SonarSource/sonarqube · error · IllegalStateException

New Code Periods Export failed after processing %d new code

Error message

New Code Periods Export failed after processing %d new code periods successfully

What it means

ExportNewCodePeriodsStep.execute() exports all NewCodePeriod entries for the project to the dump, counting successes. If any exception occurs during DB iteration or output writing, it is wrapped in an IllegalStateException reporting the number of successfully exported new code periods. The library throws this to fail the CE export task deterministically on partial export.

Source

Thrown at server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStep.java:73

        builder.clear()
          .setUuid(newCodePeriod.getUuid())
          .setProjectUuid(newCodePeriod.getProjectUuid())
          .setType(newCodePeriod.getType().name());

        if (newCodePeriod.getBranchUuid() != null) {
          builder.setBranchUuid(newCodePeriod.getBranchUuid());
        }

        if (newCodePeriod.getValue() != null) {
          builder.setValue(newCodePeriod.getValue());
        }
        output.write(builder.build());
        ++count;
      }

      LoggerFactory.getLogger(getClass()).debug("{} new code periods exported", count);
    } catch (Exception e) {
      throw new IllegalStateException(format("New Code Periods Export failed after processing %d new code periods successfully", count), e);
    }
  }

  @Override
  public String getDescription() {
    return "Export new code periods";
  }
}

View on GitHub (pinned to 184c821202)

Solutions

  1. Inspect the cause exception to identify the failing row or I/O problem
  2. Verify DB connectivity and retry the export after transient failures
  3. Clean up orphaned NEW_CODE_PERIOD rows referencing deleted branches
  4. Ensure sufficient disk space and permissions on the CE worker dump directory
Defensive patterns

Strategy: try-catch

Validate before calling

// check for orphaned new code period rows referencing missing branches beforehand
SELECT ncp.* FROM new_code_periods ncp
LEFT JOIN project_branches pb ON pb.uuid = ncp.branch_uuid
WHERE pb.uuid IS NULL;

Try / catch

try {
  step.execute(context);
} catch (IllegalStateException e) {
  LOGGER.error("New code periods export failed after {} items; cause: {}", e.getCause(), e);
}

Prevention

When it happens

Trigger: Any exception while querying NEW_CODE_PERIOD rows or writing each protobuf builder to output.write() inside execute() — e.g. SQLException on the scrolling select, conversion error for a branch reference, or dump I/O failure.

Common situations: Database timeout during export of a project with many branches; a NewCodePeriod row referencing a deleted branch failing conversion; disk full while writing the dump.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/74d07550316cfc17. Report an issue: GitHub.