{"record":{"id":"704503fca4e24983","repo":"SonarSource/sonarqube","slug":"can-only-be-called-in-sonarqube","errorCode":null,"errorMessage":"Can only be called in SonarQube","messagePattern":"Can only be called in SonarQube","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/SonarRuntimeImpl.java","lineNumber":67,"sourceCode":"    this.apiVersion = requireNonNull(apiVersion);\n    this.product = product;\n    this.sonarQubeSide = sonarQubeSide;\n  }\n\n  @Override\n  public Version getApiVersion() {\n    return apiVersion;\n  }\n\n  @Override\n  public SonarProduct getProduct() {\n    return product;\n  }\n\n  @Override\n  public SonarQubeSide getSonarQubeSide() {\n    if (sonarQubeSide == null) {\n      throw new UnsupportedOperationException(\"Can only be called in SonarQube\");\n    }\n    return sonarQubeSide;\n  }\n\n  @Override\n  public SonarEdition getEdition() {\n    if (sonarQubeSide == null) {\n      throw new UnsupportedOperationException(\"Can only be called in SonarQube\");\n    }\n    return edition;\n  }\n\n  /**\n   * Create an instance for SonarQube runtime environment.\n   */\n  public static SonarRuntime forSonarQube(Version apiVersion, SonarQubeSide side, SonarEdition edition) {\n    return new SonarRuntimeImpl(apiVersion, SonarProduct.SONARQUBE, side, edition);\n  }","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/SonarRuntimeImpl.java#L49-L85","documentation":"SonarRuntimeImpl.getSonarQubeSide() returns the SonarQube side (scanner vs compute engine vs web server) only when the runtime was created for a SonarQube environment. When the runtime has no side (e.g. built for SonarLint/standalone, where sonarQubeSide is null) it throws UnsupportedOperationException with \"Can only be called in SonarQube\". The library throws this because 'side' is meaningless outside SonarQube.","triggerScenarios":"Calling runtime.getSonarQubeSide() on a runtime created via SonarRuntimeImpl.forSonarLint(...) (or an equivalent standalone runtime) where sonarQubeSide is null.","commonSituations":"Plugin or analyzer code shared between SonarLint and SonarQube calling getSonarQubeSide() unconditionally while running inside the SonarLint IDE integration.","solutions":["Guard the call: only invoke getSonarQubeSide() when runtime.getProduct() == SonarProduct.SONARQUBE.","Branch on getProduct() and provide a fallback for SonarLint execution.","If the runtime should be SonarQube, construct it with SonarRuntimeImpl.forSonarQube(...) passing a valid SonarQubeSide."],"exampleFix":"// before\nSonarQubeSide side = runtime.getSonarQubeSide();\n\n// after\nif (runtime.getProduct() == SonarProduct.SONARQUBE) {\n  SonarQubeSide side = runtime.getSonarQubeSide();\n} else {\n  // SonarLint path: no side concept\n}","handlingStrategy":"type-guard","validationCode":"// Java\nboolean sideAvailable = runtime.getProduct() == SonarProduct.SONARQUBE;","typeGuard":"// Java\nstatic boolean hasSonarQubeSide(SonarRuntime runtime) {\n  return runtime.getProduct() == SonarProduct.SONARQUBE;\n}","tryCatchPattern":"// Java\ntry {\n  SonarQubeSide side = runtime.getSonarQubeSide();\n} catch (UnsupportedOperationException e) {\n  // SonarLint / standalone path\n}","preventionTips":["Always branch on runtime.getProduct() before using side/edition APIs.","Write plugin code paths that work identically in SonarLint.","Use SonarRuntimeImpl.forSonarQube only when the process actually runs inside SonarQube."],"tags":["sonarqube","sonarlint","unsupported-operation","runtime"],"backgroundTag":"unsupported-operation","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"}