xp icon indicating copy to clipboard operation
xp copied to clipboard

Fix XData validation for empty objects with required fields

Open Copilot opened this issue 2 months ago • 1 comments

XData validation was skipped when the data object was empty, allowing content with missing required fields to pass validation.

"x": {
    "com-enonic-app-features": {
        "all-except-folders": {}
    }
}

If all-except-folders schema defines required fields, this should fail validation but didn't.

Changes

ExtraDataValidator.java

  • Removed conditional that bypassed validation when propertySize == 0
  • Validation now runs unconditionally via OccurrenceValidator.validate()

ExtraDataValidatorTest.java

  • Added test coverage for empty XData with required fields
  • Added test coverage for empty XData with optional fields only
  • Added test coverage for populated XData with required fields

Root Cause

The validator assumed empty XData was intentionally minimal and skipped schema validation. This was incorrect—required fields must be validated regardless of whether any data is present.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • scans-in.gradle.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -XX:MaxMetaspaceSize=384m -XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>XData not validated when empty</issue_title> <issue_description>when XData is sent as empty, but it has required fields - no validation happens

        "com-enonic-app-features": {
            "all-except-folders": {}
        }
    },

validation should happen in this case, too</issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes enonic/xp#11490

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Dec 09 '25 15:12 Copilot

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 86.69%. Comparing base (302baa1) to head (9a01807).

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #11560   +/-   ##
=========================================
  Coverage     86.68%   86.69%           
  Complexity    19525    19525           
=========================================
  Files          2520     2520           
  Lines         66161    66160    -1     
  Branches       5275     5274    -1     
=========================================
+ Hits          57354    57355    +1     
+ Misses         6236     6235    -1     
+ Partials       2571     2570    -1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Dec 09 '25 16:12 codecov[bot]