Cloud Manager code quality · Java code rules (SonarQube) · updated
CQRules:CQBP-71: Avoid hardcoded apps and libs paths
CQBP-71 fires when Java code uses an absolute /apps/... or /libs/... path, such as isResourceType("/libs/foundation/components/text"). Use the relative form (foundation/components/text) so Sling resolves it through its search path and overlays keep working.
| Rule key | CQRules:CQBP-71 |
|---|---|
| Adobe's rule name | Avoid hardcoded apps and libs paths |
| Type | Code Smell |
| Severity | Minor |
| Since | 2018.4.0 |
| Checked by | SonarQube analysis of your Java code |
Why Cloud Manager flags it
Sling's resource resolver searches /apps first and /libs second. A relative resource type therefore picks up your overlay in /apps when one exists and the product version otherwise. An absolute /libs path skips the overlay; an absolute /apps path breaks when the component lives in /libs. On AEM as a Cloud Service, Adobe updates /libs continuously, so code that pins exact /libs paths is more likely to break after an automatic update.
The rule also catches comparisons of sling:resourceType values. Stored resource types are normally relative already, so comparing them against an absolute string silently returns false, which is a real bug, not just style.
Common cases and fixes
| Found | Replace with |
|---|---|
| "/apps/myco/components/teaser" | "myco/components/teaser" |
| "/libs/foundation/components/text" | "foundation/components/text" (and plan the Core Components move) |
| "/libs/wcm/foundation/components/page" | "wcm/foundation/components/page" |
| String building "/apps/" + type | Use the type as stored; call ResourceResolver.isResourceType() |
Example
Non-compliant (as in Adobe's example)
if (resource.isResourceType("/libs/foundation/components/text")) { ... }Compliant
if (resource.isResourceType("foundation/components/text")) { ... }How to fix it
- Search Java and HTL for string literals starting with /apps/ or /libs/.
- Strip the prefix for resource types; for real repository paths (for example a configuration node) read them from an OSGi configuration or a context-aware configuration.
- Prefer ResourceResolver.isResourceType(), which also follows sling:resourceSuperType inheritance.
- If the type is a Foundation component, note it for the Core Components migration (see LegacyFoundationComponentUsage).
Does it stop the pipeline?
Code smells feed the Maintainability Rating, which is based on the total estimated fix time as a share of development time, not on any single finding. One finding rarely moves it, but hundreds can push the rating below A, which is an important failure: the pipeline pauses until someone overrides or fixes it.
If a finding is a genuine false positive, Adobe's code quality page lets you annotate the code with @SuppressWarnings and the rule ID. In a full-stack pipeline, important failures can be overridden by a deployment manager, project manager or business lead; in a code-quality-only pipeline they cannot.
Questions
Does this rule apply to HTL files?
Adobe's rule is a SonarQube Java rule, so it reports Java. Absolute paths in HTL data-sly-resource attributes cause the same overlay problem and are worth fixing at the same time.
Is /conf also flagged?
No, the rule is about /apps and /libs. /conf paths are better read through context-aware configuration anyway.
Is it safe to bulk-replace?
For resource-type strings, yes. For paths used to read nodes directly, check each one: some really are repository locations and should move to configuration.
See the Cloud Service blockers in your code before Cloud Manager shows them. The free Surge Migrate readiness scan reads a repository zip or a Best Practices Analyzer CSV in your browser and lists them with file, fix and effort. Nothing is uploaded.
Sources
- Adobe: Custom code quality rules (checked 10 Nov 2026)
- Adobe: Code quality testing in Cloud Manager (checked 10 Nov 2026)
Rule key, type, severity and version are as listed on Adobe's page, checked 10 Nov 2026. Explanations and examples are ours unless marked as Adobe's.