Review main Merged

67044[TASK] Deprecate ControllerContext::getFlashMessageQueue()

Alexander Schnitzler CR +2 V +2 Normal +109 −18 updated 12/09/20, 09:38

Commit message

With this patch method getFlashMessageQueue() of ControllerContext
is deprecated and the core avoids using it.

A trigger_error call will be implemented in another patch set
which deprecates the whole ControllerContext object.

Review

  • Code review CR +2 Done
    • Daniel Goerz +2
    • Oli Bartsch +1
    • Benni Mack +1
  • Verified V +2 Done
    • Daniel Goerz +2
    • Oli Bartsch +1
    • Benni Mack +1
    • TYPO3com +1 CI

Issues 1

Files 12

Review log 1925

  1. Alexander Schnitzler uploaded patch set 1 12/07/20, 12:38

  2. Alexander Schnitzler wrote 12/07/20, 12:39

    Topic set to extbase
  3. TYPO3com voted on patch set 1 V -1 12/07/20, 12:49 Completed build in 11m 04s on Mon, 7 Dec, 12:49 PM Test Summary: 12 of 32654 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7900

  4. Alexander Schnitzler uploaded patch set 2 12/07/20, 12:50

  5. TYPO3com voted on patch set 2 V +1 12/07/20, 12:59 Completed build in 08m 49s on Mon, 7 Dec, 12:59 PM Test Summary: 32413 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7902

  6. Alexander Schnitzler uploaded patch set 3 12/07/20, 13:45

  7. TYPO3com voted on patch set 3 V -1 12/07/20, 13:56 Completed build in 10m 57s on Mon, 7 Dec, 01:56 PM Test Summary: 31527 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7904

  8. TYPO3com voted on patch set 3 V +1 12/07/20, 14:25 Completed build in 51m 14s on Mon, 7 Dec, 02:25 PM Test Summary: 32413 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7904

  9. Oli Bartsch commented on patch set 3 12/07/20, 16:08

    ActionController.php:188

    Why do we declare it nullable? AFAICS it will be set in the injectInternalFlashMessageService method. Problem with being nullable is that you have to check for null on every access then.

    ActionController.php:193 Unresolved

    Same as above.

    ActionController.php:867

    This direct access will then result in possible null pointer.
  10. Alexander Schnitzler commented on patch set 3 12/07/20, 16:25

    ActionController.php:188 Reply

    Yeah, that's walking on a thin line here. Technically, the property is not initialized on object construction (right after the constructor) and there is no guarantee the inject method is called. You can theoretically access this property before it's initialized and trigger a fatal error.

    ActionController.php:867 Reply

    If properly constructed (via DI), this is not the case. If creation a controller via new and accessing internalFlashMessageService, a non initialized exception occurs. Question (imho) is what is closer to proper code according to the language specs.
  11. Oli Bartsch commented on patch set 3 12/07/20, 16:42

    ActionController.php:188 Reply

    Yes, that's basically also the case for all other properties which get injected. All of them will lead to an exception / error if accessed on an instance which is not yet not properly initialized.

    ActionController.php:867 Reply

    Since this class heavily depends on proper construction with DI, I would actually prefer the "not initialized" exception here. I see no use-case on which it's valid that these properties are null. I mean, if this class is not properly constructed, this should trigger the error, not the null pointer in the later code. It would then be one more step to find the real cause.
  12. Alexander Schnitzler commented on patch set 3 12/07/20, 16:54

    ActionController.php:188 Reply

    No, it's not since the other properties don't have type hints.

    ActionController.php:867 Reply

    It actually does. See this example: https://3v4l.org/ob66k If not properly initialized, a fatal error is thrown that tells you about the uninitialized property before php evaluates the method call which would throw a null pointer exception. That happens for uninitialized properties without type hint.
  13. Alexander Schnitzler commented on patch set 3 12/07/20, 17:02

    ActionController.php:188 Reply

    Sorry, you are right of course...

    ActionController.php:867 Reply

    lol, that snippets proves me wrong actually. You are right of course.
  14. Oli Bartsch commented on patch set 3 12/07/20, 17:17

    ActionController.php:188 Reply

    Sorry, what I meant was that the properties without type hint will lead to an "Call to a member function on null" error. This shows that having this class not properly initialized will lead to errors. No matter if nullable or not. And in this case I personally prefer an error telling me that some properties were not properly initialized instead of a null pointer.

    ActionController.php:867 Reply

    It only does because it's not declared as nullable. Adding `private ?FlashMessageService $flashMessageService = null;` to your example leads to `Fatal error: Uncaught Error: Call to a member function getFlashMessageQueue() on null`. https://3v4l.org/BLHAK - That's what I personally want to avoid since the "must not be accessed before initialization" error takes you directly to the root cause.
  15. Alexander Schnitzler commented on patch set 3 12/07/20, 17:35

    ActionController.php:188 Reply

    Ack

    ActionController.php:867 Reply

    Yep, that's why it proves me wrong. I had the exact opposite in mind. Sometimes my brain doesnt work right. ^^ Will push a new patch set.
  16. Alexander Schnitzler uploaded patch set 4 12/07/20, 17:37

  17. Alexander Schnitzler commented on patch set 4 12/07/20, 17:40

    ActionController.php:867 Reply

    Ack
  18. TYPO3com voted on patch set 4 V -1 12/07/20, 17:51 Completed build in 13m 38s on Mon, 7 Dec, 05:51 PM Test Summary: 32411 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7932

  19. Oli Bartsch commented on patch set 4 12/07/20, 18:09

    ActionController.php:867 Reply

    No problem. It's great that we could work that out! :)
  20. Alexander Schnitzler uploaded patch set 5 12/08/20, 08:47

  21. TYPO3com voted on patch set 5 V +1 12/08/20, 08:56 Completed build in 08m 52s on Tue, 8 Dec, 08:56 AM Test Summary: 32411 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7952

  22. Benni Mack voted on patch set 5 V +1 CR +1 12/08/20, 16:07

  23. Oli Bartsch voted on patch set 5 V +1 CR +1 12/09/20, 09:31

  24. Daniel Goerz voted on patch set 5 V +2 CR +2 12/09/20, 09:38

  25. Daniel Goerz merged patch set 6 12/09/20, 09:38