Review main Ready for review Orphaned

89055[BUGFIX] Improve error details when property access fails in validator

Stefan Froemken CR 0 V -1 Normal +68 −5 updated 04/22/26, 10:28

Commit message

When a property cannot be accessed in `AbstractGenericObjectValidator`,
the thrown exception now includes detailed information about the
possible causes:

- The property does not exist in the class
- No public visibility or missing getter methods (get*/has*/is*)
- The property is uninitialized (typed property, PHP 7.4+)
- The property is not mapped via TCA (checked via DataMapFactory)

This helps developers better understand validation errors and improves
debuggability during development and testing.

Test this change

Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch

Check out patch set 5
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/55/89055/5 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/55/89055/5 && git cherry-pick FETCH_HEAD

Review

  • Code review CR 0 Needs a vote
  • Verified V -1 Blocked
    • core-ci -1 CI

Issues 1

Files 1

Review log 2429

Show 34 earlier messages
  1. Stefan Froemken uploaded patch set 1 04/11/25, 11:59

  2. core-ci voted on patch set 1 V -1 04/11/25, 12:06 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77524

  3. Stefan Froemken uploaded patch set 2 V -1 04/11/25, 12:17

  4. Stefan Froemken commented on patch set 2 04/11/25, 12:23

    As this is an abstract class I would prevent to inject DataMapFactory via constructor arguments
  1. core-ci voted on patch set 2 V +1 04/11/25, 12:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77528

  2. Garvin Hicking commented on patch set 2 04/11/25, 17:20

    Is this any change in buggy behavior, or would this rather be a "[TASK]"? (haven't reviewed properly)
  3. Lina Wolf commented on patch set 2 04/12/25, 05:30

    Reply

    In my eyes it is a bug as the previous error message did not cover all cases that can cause the error
  4. Lina Wolf commented on patch set 2 V -1 04/12/25, 05:45

    I just tried this patch within our project in question. I have the following model: ``` class Entry extends AbstractEntity { public function __construct( protected int $status = 0, #[Validate(['validator' => 'NotEmpty'])] protected string $content = '', protected ?User $user = null, protected ?Newsentry $news = null, protected ?Votingtopic $topic = null, ) {} ``` And removed `topic` from the TCA and cleared the cache. Afterwards I get error ``` (1/1) #1546632293 RuntimeException Error accessing property "MyVendor\MyExtension\Domain\Model\Entry::topic": The property "topic" is of type "MyVendor\MyExtension\Domain\Model\Votingtopic" and is uninitialized (PHP 8 "uninitialized" state). The property "topic" is not configured in TYPO3 TCA. ``` Even though the property should have been initialized?
  5. Stefan Froemken commented on patch set 2 04/13/25, 08:16

    Reply

    Since PHP 8 I initialize all of my properties. Set a default directly at the property or within constructor. That it also works with uninitialized properties is a very magically job of extbase internals. You can prevent the issue by either proper initialization of your property OR by setting TCA. So both solutions are valid. Solving both problems in your extension will just make your extension less "magically" and provides strong defaults.
  6. Lina Wolf commented on patch set 2 04/13/25, 08:55

    Reply

    To me it seems like default values in constructor promotion behave differently from properties defined in the class with a default value. Maybe this is due to some Extbase Magic
  7. Lina Wolf commented on patch set 2 CR +1 V +1 04/13/25, 09:47

    Reply

    It seems like constructor promotion is currently not supported by Extbase. I opened a separate issue: https://forge.typo3.org/issues/106565 Other then that the error messages are a great improvement and work as expected.
  8. Stefan Bürk commented on patch set 2 04/27/25, 23:49

    php 7.4+ .. relates to "typed properties without initialisation" which is only possible since php7.4. With PHP8 and using CPP (incorrectly) based on not really understanding this tit's kind different chain, ending in the pure fact that a typed property is not initalized. Before typed properties (php7.4) properties have been always initialized at least as null if not defined otherwise with a default assignment on property definition level.
  9. Stefan Froemken updated the commit message in patch set 3 CR +1 V +1 06/06/25, 06:04

  10. Stefan Froemken commented on patch set 3 06/06/25, 06:04

    Reply

    Done
  11. core-ci voted on patch set 3 V +1 06/06/25, 06:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79967

  12. Simon Schaufelberger voted on patch set 3 CR +1 06/06/25, 06:25

  13. Garvin Hicking commented on patch set 3 06/06/25, 06:28

    AbstractGenericObjectValidator.php:119

    ```suggestion 'The property "%s" is of type "%s" and is uninitialized (PHP "uninitialized" state). ', ``` IMO we should either use "PHP 8+" or just "PHP" here, fixating it to a version number will be outdated at some point in the future and would require to alter the exception message. I think we could just drop the version number?
  14. Stefan Froemken commented on patch set 3 06/06/25, 08:23

    AbstractGenericObjectValidator.php:119 Reply

    Fix applied.
  15. Stefan Froemken commented on patch set 4 CR +1 V +1 06/06/25, 08:25

    Published edit on patch set 3.
  16. core-ci voted on patch set 4 V +1 06/06/25, 08:34 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79974

  17. Lina Wolf commented on patch set 4 CR +1 06/06/25, 09:15

    looks good to me
  18. Simon Schaufelberger voted on patch set 4 CR +1 06/06/25, 10:41

  19. Mathias Brodala commented on patch set 4 06/13/25, 07:12

    AbstractGenericObjectValidator.php:131 Unresolved

    Instead of "TYPO3" (what else?) we should mention the TCA table name instead.
  20. Garvin Hicking commented on patch set 4 06/13/25, 07:42

    I like the improvement in the clarity of the error message, but I feel this is now so much logic it would warrant to be its own helper method, or even part of ObjectAccess::isPropertyGettable...?
  21. Mathias Brodala commented on patch set 4 06/13/25, 07:52

    Reply

    If you mean with the latter that that API can throw more specific exceptions then it'd indeed be a non-breaking option. Otherwise we'd need a new API to pass back a structured result.
  22. Garvin Hicking commented on patch set 4 06/13/25, 08:05

    Reply

    Yeah, maybe like a new method like 'evaluateIsPropertyGettable()' that calls 'isPropertyGettable' and then does all of this and natively through the exception. So that the validator's getPropertyValue() only calls this new API method and has no other "own" code for this. IMO it's not in the domain of the validator to do all these property checks. (I also thought about adding a parameter like 'bool $throwExceptions = false' to the 'isPropertyGettable' method to toggle this, but this would be more hackish)
  23. Mathias Brodala commented on patch set 4 06/13/25, 08:14

    Reply Unresolved

    Actually we can use the advertised PropertyNotAccessibleException and actually catch it accordingly everywhere. This way we have no API/behavior change. But maybe add an Important RST that people really should take care to catch PropertyNotAccessibleException when calling getProperty(). Consequently isPropertyGettable() may not be necessary here anymore.
  24. Benni Mack updated the commit message in patch set 5 CR +1 V +1 04/22/26, 06:33

  25. core-ci voted on patch set 5 V -1 04/22/26, 07:21 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100734