{"record":{"id":"4aa536eca578bcf9","repo":"SonarSource/sonarqube","slug":"format-can-not-load-from-classpath-edition-file-p","errorCode":null,"errorMessage":"format(CAN_NOT_LOAD_FROM_CLASSPATH, EDITION_FILE_PATH)","messagePattern":"format\\(CAN_NOT_LOAD_FROM_CLASSPATH, EDITION_FILE_PATH\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/MetadataLoader.java","lineNumber":95,"sourceCode":"  private static String getParamFromFile(System2 system, String filePath) {\n    URL url = system.getResource(filePath);\n    try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8)) {\n      return scanner.nextLine();\n    } catch (IOException e) {\n      throw new IllegalStateException(format(CAN_NOT_LOAD_FROM_CLASSPATH, filePath), e);\n    }\n  }\n\n  public static SonarEdition loadEdition(System2 system) {\n    URL url = system.getResource(EDITION_FILE_PATH);\n    if (url == null) {\n      return SonarEdition.COMMUNITY;\n    }\n    try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8)) {\n      String editionInFile = scanner.nextLine();\n      return parseEdition(editionInFile);\n    } catch (IOException e) {\n      throw new IllegalStateException(format(CAN_NOT_LOAD_FROM_CLASSPATH, EDITION_FILE_PATH), e);\n    }\n  }\n\n  static SonarEdition parseEdition(String edition) {\n    String str = trimToEmpty(edition.toUpperCase(Locale.ENGLISH));\n    try {\n      return SonarEdition.valueOf(str);\n    } catch (IllegalArgumentException e) {\n      throw new IllegalStateException(format(\"Invalid edition found in '%s': '%s'\", EDITION_FILE_PATH, str));\n    }\n  }\n}\n","sourceCodeStart":77,"sourceCodeEnd":108,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/MetadataLoader.java#L77-L108","documentation":"loadEdition reads sonar-edition.txt from the classpath to determine the SonarQube edition. If the resource URL exists but the stream cannot be read (IOException), it throws IllegalStateException with a CAN_NOT_LOAD_FROM_CLASSPATH message naming EDITION_FILE_PATH. It only reaches this path when the resource URL was found but unreadable.","triggerScenarios":"Calling SonarRuntimeImpl.getEdition() or MetadataLoader.loadEdition(system) when sonar-edition.txt is present on the classpath but its stream fails to open (corrupted jar, IO error reading the packaged resource).","commonSituations":"Damaged SonarQube installation jar; incomplete deployment where the edition file was partially packaged; file-system I/O errors in the deployment environment.","solutions":["Verify the integrity of the sonar-application jar (re-download / reinstall).","Check the wrapped IOException cause for the real IO failure.","Ensure sonar-edition.txt is packaged and readable inside the deployed artifact."],"exampleFix":"// before: reading edition from a corrupted install fails\n// after: reinstall a clean distribution and confirm the jar contains the resource\nunzip -l sonar-application.jar | grep sonar-edition.txt","handlingStrategy":"try-catch","validationCode":"// Java\nURL url = system.getResource(\"/sonar-edition.txt\");\nif (url == null) { /* falls back to COMMUNITY upstream */ }","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n  SonarEdition edition = runtime.getEdition();\n} catch (IllegalStateException e) {\n  // log and default to SonarEdition.COMMUNITY or recheck installation integrity\n}","preventionTips":["Verify distribution jar integrity after deployment (checksums).","Avoid modifying files inside installed jars.","Monitor disk health on servers hosting the SonarQube installation."],"tags":["classpath","edition","sonarqube-plugin"],"backgroundTag":"resource-not-found","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}