Overview

With the latest HEAD, I'm getting following error after following the installation steps and navigating to XB:

Error: Typed property Drupal\experience_builder\EventSubscriber\ApiMessageValidator::$validatorBuilder must not be accessed before initialization in Drupal\experience_builder\EventSubscriber\ApiMessageValidator->isValidationEnabled() (line 165 of modules/custom/experience_builder/src/EventSubscriber/ApiMessageValidator.php).
Drupal\experience_builder\EventSubscriber\ApiMessageValidator->shouldValidate() (Line: 93)
Drupal\experience_builder\EventSubscriber\ApiMessageValidator->onMessage() (Line: 246)
Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}() (Line: 206)
Symfony\Component\EventDispatcher\EventDispatcher->callListeners() (Line: 56)
Symfony\Component\EventDispatcher\EventDispatcher->dispatch() (Line: 159)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 709)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Proposed resolution

User interface changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lauriii created an issue. See original summary.

wim leers’s picture

Assigned: Unassigned » wim leers
wim leers’s picture

Reproduced. It required me to undo

7. If you want to run *all* tests locally, including the OpenAPI spec one: `composer require league/openapi-psr7-validator webflo/drupal-finder devizzent/cebe-php-openapi --dev`

… but that is supposed to be optional.

#3466555: Also validate request bodies against the OpenAPI spec introduced this, and likely that's my fault 😅

wim leers’s picture

Turns out @traviscarden introduced this regression by making this change:

  protected $validator;
  private ?ValidatorBuilder $validator;

👆 that causes PHP to be more strict, and it no longer defaults to NULL by default! 🤪

Thankfully the fix is trivial:

diff --git a/src/EventSubscriber/ApiMessageValidator.php b/src/EventSubscriber/ApiMessageValidator.php
index 0ffb1216..17baca2d 100644
--- a/src/EventSubscriber/ApiMessageValidator.php
+++ b/src/EventSubscriber/ApiMessageValidator.php
@@ -44,7 +44,7 @@ final class ApiMessageValidator implements EventSubscriberInterface {
    *
    * @var \League\OpenAPIValidation\PSR7\ValidatorBuilder|null
    */
-  private ?ValidatorBuilder $validatorBuilder;
+  private ?ValidatorBuilder $validatorBuilder = NULL;
 
   /**
    * Constructs an API Message Validator object.

wim leers’s picture

Title: Error: Typed property Drupal\experience_builder\EventSubscriber\ApiMessageValidator::$validatorBuilder must not be accessed before initialization » [regression] PHP fatal error `ApiMessageValidator::$validatorBuilder must not be accessed before initialization` when `league/openapi-psr7-validator` is not installed

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Active » Needs review
wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Manually tested again, merging this single-line MR without additional review to avoid others having their productivity impacted by this 😬

What a wild ride! 🤠 This was definitely nobody's fault, it's just a tiny, super obscure thing. Chances of such a regression getting reintroduced are vanishingly thin.

🚢

  • Wim Leers committed 17953cdc on 0.x
    Issue #3471201 by Wim Leers, lauriii: [regression] PHP fatal error `...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.