{"record":{"id":"3d4edff3fc4e0751","repo":"SonarSource/sonarqube","slug":"analysis-failed-reason-pot","errorCode":null,"errorMessage":"Analysis Failed.\n---------------------\nREASON: Potential Out-Of-Memory (OOM) Risk Detected.\nThe Compute Engine detected an excessively large volume of potential file moves: %d added files and %d removed files.\n- Estimated heap needed for File Move Detection: %.1f GB.\n- Detected heap size allocated to Compute Engine: %.1f GB.\nThe scan failed proactively to avoid an out-of-memory failure on the server.\n\nNEXT STEPS (Choose One):\n\n  1. Unintended Move (Mistake):\nPlease revert the project structure to the previous commit and re-run the analysis.\n\n  2. Intended Move (Legitimate Restructure):\nThe volume of moved/renamed files is too large to be processed. Please restore the old structure, and perform this move in multiple batches, each followed by analysis.\n---------------------\n","messagePattern":"Analysis Failed\\.\n---------------------\nREASON: Potential Out-Of-Memory \\(OOM\\) Risk Detected\\.\nThe Compute Engine detected an excessively large volume of potential file moves: %d added files and %d removed files\\.\n- Estimated heap needed for File Move Detection: %\\.1f GB\\.\n- Detected heap size allocated to Compute Engine: %\\.1f GB\\.\nThe scan failed proactively to avoid an out-of-memory failure on the server\\.\n\nNEXT STEPS \\(Choose One\\):\n\n  1\\. Unintended Move \\(Mistake\\):\nPlease revert the project structure to the previous commit and re-run the analysis\\.\n\n  2\\. Intended Move \\(Legitimate Restructure\\):\nThe volume of moved/renamed files is too large to be processed\\. Please restore the old structure, and perform this move in multiple batches, each followed by analysis\\.\n---------------------\n","errorType":"exception","errorClass":"TooManyFileMovesDetectedException","httpStatus":null,"severity":"error","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/HeapSizeCheckerImpl.java","lineNumber":44,"sourceCode":"  private final long maxMemory;\n\n  public HeapSizeCheckerImpl() {\n    this(Runtime.getRuntime().maxMemory());\n  }\n\n  @VisibleForTesting\n  HeapSizeCheckerImpl(long maxMemory) {\n    this.maxMemory = maxMemory;\n  }\n\n  @Override\n  public void checkHeapLimits(int totalAddedFiles, int totalRemovedFiles) {\n    long matrixSize = (long) totalAddedFiles * totalRemovedFiles;\n    double heapSizeInGb = toGb(maxMemory);\n    double estimatedHeapNeededInGb = toGb(matrixSize * Integer.BYTES);\n\n    if (heapSizeInGb <= estimatedHeapNeededInGb) {\n      throw new TooManyFileMovesDetectedException(totalAddedFiles, totalRemovedFiles, heapSizeInGb, estimatedHeapNeededInGb);\n    }\n  }\n\n  private static double toGb(long bytes) {\n    return (double) bytes / 1024.0F / 1024.0F / 1024.0F;\n  }\n\n}\n","sourceCodeStart":26,"sourceCodeEnd":53,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/HeapSizeCheckerImpl.java#L26-L53","documentation":"HeapSizeCheckerImpl.checkHeapLimits() estimates the heap needed by the File Move Detection step as addedFiles × removedFiles × 4 bytes (an int matrix) and compares it to the Compute Engine's max heap (maxMemory). If the estimate exceeds or equals the available heap, it throws TooManyFileMovesDetectedException with this detailed message, aborting the analysis proactively instead of letting the CE crash with an OutOfMemoryError.","triggerScenarios":"Running a project analysis where the report adds N files and removes M files such that N*M*sizeof(int) >= CE heap — typical of a large-scale directory move/rename committed in one analysis, or a branch scan against a drastically restructured tree.","commonSituations":"Renaming a top-level package/directory touching thousands of files at once, migrating a monorepo layout in a single commit, or running on a CE with a small -Xmx while the project has tens of thousands of moved files.","solutions":["Revert the restructuring and redo it in multiple smaller batches, running an analysis after each batch (as the message's NEXT STEPS suggests)","Increase the Compute Engine heap: raise SONAR_CE_JAVAOPTS/-Xmx (e.g. -Xmx8g) so it exceeds added×removed×4 bytes","If the mass add/remove is unintended, restore the previous project structure and re-run the analysis"],"exampleFix":"// before: one giant rename analyzed at once\n$ git mv oldpkg newpkg  # 20,000 files\n$ sonar-scanner  // fails\n// after: batch the move\n$ git mv oldpkg/sub1 newpkg/sub1 && sonar-scanner\n$ git mv oldpkg/sub2 newpkg/sub2 && sonar-scanner\n// or raise heap\nSONAR_CE_JAVAOPTS=\"-Xmx8g\"","handlingStrategy":"try-catch","validationCode":"// estimate before launching analysis\nlong added = countAddedFiles(diff);\nlong removed = countRemovedFiles(diff);\ndouble neededGb = (double) (added * (long) removed * Integer.BYTES) / 1024 / 1024 / 1024;\nif (neededGb >= ceHeapGb) {\n  System.out.println(\"Split the move into batches or increase CE -Xmx above \" + neededGb + \" GB\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  analysis = computeEngine.analyze(project);\n} catch (TooManyFileMovesDetectedException e) {\n  // message includes added/removed counts and needed vs allocated heap\n  logger.warn(\"File move detection aborted: {} added / {} removed files\", e.getTotalAddedFiles(), e.getTotalRemovedFiles());\n  // batch the restructure or raise -Xmx, then retry\n}","preventionTips":["Perform large directory/package renames in multiple batches with an analysis after each","Size the Compute Engine heap (SONAR_CE_JAVAOPTS -Xmx) to exceed addedFiles*removedFiles*4 bytes","Watch the file-move detection logs when scanning branches with big restructurings","If the mass add/remove is accidental, restore the structure instead of raising heap"],"tags":["compute-engine","oom","file-move","heap"],"backgroundTag":"payload-too-large","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"}