HomeTroubleshooting Hub › Sling Model injection failures

Sling Model injection failures

Purpose: Diagnose models that adapt to null or render with empty fields.

Who this page is for

AudienceWhy it matters to you
Backend engineersDaily dev-loop debugging
Frontend engineersReading the symptoms from HTL

Two distinct symptoms

SymptomMeaning
data-sly-use.model yields null (whole model absent)Adaptation failed
Model present, some fields null/defaultsIndividual injection failed (OPTIONAL strategy hides it)

Adaptation returns null — checklist

  1. Registered? /system/console/status-slingmodels lists all models — is yours there, for the right adaptable?

Missing ⇒ bundle's Sling-Model-Packages/annotation processing or bundle not Active (bundle page).

  1. Adaptable mismatch — model declares Resource but HTL adapts from request (or vice versa). adaptables={…} can take both; injectors differ per adaptable (@ScriptVariable needs request).
  2. A REQUIRED injection failed — default strategy without OPTIONAL: any missing property nulls the whole model. error.log at DEBUG for org.apache.sling.models says exactly which injector failed — this log line is the single most useful fact on this page.
  3. @PostConstruct threw — exception in error.log; model becomes null.
  4. Wrong class name in data-sly-use (package rename, typo) — HTL reports "identifier not found" style errors.

Fields empty though content exists

CauseFix
Property name ≠ field name@Named("jcr:title") etc.
Dialog saved to a different node/prefixInspect actual content in CRXDE vs model expectations (dialog issues)
Type mismatch (String saved, long injected)TypeHints in dialog or String field + parse in @PostConstruct
@ChildResource shape mismatchMultifield composite vs flat — align dialog and model
Injecting on request-adaptable via resource-only injector or vice versaMatch injector to adaptable

Make it never happen again

OPTIONAL strategy + explicit defaults + a unit test with empty content (testing) turns this whole page from prod symptom into red test at build time.

Quick navigation