Review main Merged

85677[BUGFIX] Handle that FileLinkHandler:resolveFile() can return null

Thomas Hohn CR +2 V +2 Normal +76 −5 updated 10/08/24, 12:16

Commit message

In the method FileLinkHandler:resolveHandlerData() the call
to FileLinkHandler:resolveFile() handles the FileDoesNotExistException
correctly. But if it returns null this will lead to a type error.
This patch handles the null value properly.

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Stefan Bürk +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Stefan Bürk +1
    • core-ci +1 CI

Issues 1

Files 4

Review log 76101

Show 5676 earlier messages
  1. Thomas Hohn uploaded patch set 1 08/19/24, 07:04

  2. core-ci voted on patch set 1 V +1 08/19/24, 07:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63750

  3. Thomas Hohn uploaded patch set 2 V +1 08/19/24, 07:59

  4. core-ci voted on patch set 2 V -1 08/19/24, 08:07 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63755

  5. Stefan Bürk commented on patch set 2 08/19/24, 08:25

    FileLinkHandler.php:102

    Should `getFileObject` not throw already the FileDoesNotExistException ? If not, that method should be fixed as it states to do so. Makes this check and exception useless.
  6. Thomas Hohn uploaded patch set 3 V -1 08/19/24, 10:02

  7. core-ci voted on patch set 3 V -1 08/19/24, 10:07 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63758

  8. Thomas Hohn uploaded patch set 4 V -1 08/19/24, 10:15

  9. core-ci voted on patch set 4 V +1 08/19/24, 10:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63759

  10. Thomas Hohn commented on patch set 4 08/19/24, 10:31

    FileLinkHandler.php:102 Reply

    Yes and no - the method calls createFileObject which has a rather funky return type - so I believe it's safest to do so. In addition I tried making getFileObject throw an FileDoesNotExistException - but for some weird reason that doesnt see to work - or maybe my test is wrong?
  11. Thomas Hohn commented on patch set 4 08/19/24, 17:40

    FileLinkHandler.php:102 Reply

    Done
  12. Chris Müller updated the commit message in patch set 5 V +1 08/19/24, 17:53

  13. Chris Müller updated the commit message in patch set 6 08/19/24, 17:53

  14. core-ci voted on patch set 5 V +1 08/19/24, 17:59 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63781

  15. Markus Klein commented on patch set 6 08/19/24, 18:00

    FileLinkHandler.php:103

    do we really need these specific checks? Simply checking for null should be sufficient, right?
  16. core-ci voted on patch set 6 V +1 08/19/24, 18:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63782

  17. Thomas Hohn commented on patch set 6 08/19/24, 18:52

    FileLinkHandler.php:103 Reply

    I think I had that in one of the first versions but no sure if php was complaining over it
  18. Thomas Hohn uploaded patch set 7 V +1 08/19/24, 19:01

  19. core-ci voted on patch set 7 V +1 08/19/24, 19:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63784

  20. Thomas Hohn commented on patch set 7 08/19/24, 19:08

    FileLinkHandler.php:103 Reply

    So changes it to !== null - seems to work
  21. Markus Klein commented on patch set 7 08/19/24, 20:06

    FileLinkHandler.php:95

    I think we can adjust the return type directly. We are narrowing down and not widening up.

    Important-104659-FileLinkHandlerResolveFile.rst:17

    to **a** type error
  22. Thomas Hohn uploaded patch set 8 V +1 08/19/24, 20:43

  23. Thomas Hohn commented on patch set 8 08/19/24, 20:44

    FileLinkHandler.php:95 Reply

    Done

    Important-104659-FileLinkHandlerResolveFile.rst:17 Reply

    Done
  24. core-ci voted on patch set 8 V +1 08/19/24, 20:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63786

  25. Thomas Hohn commented on patch set 7 08/20/24, 04:33

    FileLinkHandler.php:103 Reply

    Done
  26. Andreas Kienast commented on patch set 8 08/20/24, 05:26

    I wonder whether we need the ReST at all. `FileLinkHandler` isn't intended to be used directly, but is part of the upper Link Handler API and consumed by it.

    Important-104659-FileLinkHandlerResolveFile.rst:23

    Please do not describe the previous state as status quo as this isn't true anymore with your patch. Instead, describe properly what has changed and why it was necessary.
  27. Thomas Hohn uploaded patch set 9 V +1 08/20/24, 05:41

  28. Thomas Hohn commented on patch set 8 08/20/24, 05:41

    Important-104659-FileLinkHandlerResolveFile.rst:23 Reply

    Done
  29. core-ci voted on patch set 9 V +1 08/20/24, 05:46 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63801

  30. Thomas Hohn commented on patch set 9 08/20/24, 05:48

    Reply

    Since it's neither marked as public nor private - I find it ok ;-)
  31. Simon Schaufelberger updated the commit message in patch set 10 V +1 10/04/24, 12:13

  32. Markus Klein voted on patch set 10 CR +1 V +1 10/04/24, 12:15

  33. Simon Schaufelberger commented on patch set 10 10/04/24, 12:15

    FileLinkHandler.php:110

    would it make sense to add some more context like the uid or the identifier? Then it would make sense to throw the exception above.
  34. Thomas Hohn commented on patch set 10 10/04/24, 12:31

    FileLinkHandler.php:110 Reply

    Depends on if there is a case there $data doesn't contain an uid nor identifier - then you would still need the fallback FileDoesNotExistException. On the other hand you could provide a more specific context if you add the exceptions in the if blocks?
  35. core-ci voted on patch set 10 V -1 10/04/24, 12:31 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67079

  36. Simon Schaufelberger commented on patch set 10 10/04/24, 16:05

    FileLinkHandler.php:110 Reply

    yes, that is exactly what i mean. more context. that is why i would throw them above with a more detailed messsage.
  37. Thomas Hohn uploaded patch set 11 CR +1 V +1 10/04/24, 17:25

  38. Thomas Hohn commented on patch set 10 10/04/24, 17:36

    FileLinkHandler.php:110 Reply

    Done
  39. core-ci voted on patch set 11 V -1 10/04/24, 17:41 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67108

  40. Thomas Hohn uploaded patch set 12 V -1 10/04/24, 18:11

  41. core-ci voted on patch set 12 V +1 10/04/24, 18:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67110

  42. Markus Klein commented on patch set 12 10/04/24, 18:39

    ResourceFactory.php:184

    How can this be `null`? `createFileObject` does not return `null`. What do I miss?
  43. Thomas Hohn commented on patch set 12 10/04/24, 20:18

    ResourceFactory.php:184 Reply

    PHPStand complained about: 100 Strict comparison using === between TYPO3\CMS\Core\Resource\File and null will always evaluate to false. So it just might to be a == at L100 in FileLinkHandler and then revert the signature to @return File But my PHPStorm also is under the impression that getFileObject can return null even though I can see how that should happend
  44. Thomas Hohn commented on patch set 12 10/04/24, 20:22

    ResourceFactory.php:184 Reply

    Or should the baseline be updated?
  45. Thomas Hohn uploaded patch set 13 V +1 10/05/24, 05:24

  46. core-ci voted on patch set 13 V +1 10/05/24, 05:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67131

  47. Thomas Hohn commented on patch set 13 10/05/24, 05:43

    ResourceFactory.php:184 Reply

    @markus.klein@typo3.org - I hope this is better?
  48. Thomas Hohn uploaded patch set 14 V +1 10/05/24, 06:07

  49. core-ci voted on patch set 14 V +1 10/05/24, 06:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67134

  50. Markus Klein commented on patch set 14 10/05/24, 20:52

    FileLinkHandler.php:100

    I think phpstan is right here, this will never happen, as getFileObject either throws or returns a file.
  51. Thomas Hohn uploaded patch set 15 V +1 10/06/24, 06:11

  52. Thomas Hohn commented on patch set 15 10/06/24, 06:24

    FileLinkHandler.php:100 Reply

    Kind of confused - now that I removed the check, the test fails and indicates that it can return null...
  53. core-ci voted on patch set 15 V -1 10/06/24, 06:28 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67180

  54. Markus Klein commented on patch set 15 10/06/24, 21:17

    FileLinkHandler.php:100 Reply

    Maybe phpstan is wrong? wouldn't be the first time.
  55. Markus Klein commented on patch set 15 10/06/24, 21:22

    FileLinkHandler.php:100 Reply

    Ah, it's not phpstan. You mock the whole ResourceStorage, that means it will return null of course.
  56. Thomas Hohn commented on patch set 15 10/07/24, 05:25

    FileLinkHandler.php:100 Reply

    If you have time to help fixing/proposing how it can/should be fixed - I would appreciate that
  57. Markus Klein commented on patch set 15 10/07/24, 08:02

    I studied the tests. IMO these unit tests are not really useful, they are not actually testing validity of identifiers/uids, due to ResourceFactory being mocked away. The only sensible way to test this would be a functional test. So we either add one there, or we drop the tests completely.
  58. Thomas Hohn uploaded patch set 16 V -1 10/07/24, 09:27

  59. core-ci voted on patch set 16 V +1 10/07/24, 09:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67216

  60. Thomas Hohn commented on patch set 16 10/07/24, 09:47

    Reply

    Converted tests into functional tests

    FileLinkHandler.php:100 Reply

    Changes tests
  61. Thomas Hohn uploaded patch set 17 V +1 10/07/24, 09:48

  62. Andreas Kienast commented on patch set 17 10/07/24, 09:51

    Important-104659-FileLinkHandlerResolveFile.rst:6

    please add "throws exception" or alike to make it clear why it's important
  63. core-ci voted on patch set 17 V +1 10/07/24, 10:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67217

  64. Markus Klein commented on patch set 17 10/07/24, 10:12

    FileLinkHandler.php:100 Reply

    Acknowledged
  65. Markus Klein commented on patch set 18 V +1 10/07/24, 10:13

    Published edit on patch set 17.
  66. Markus Klein commented on patch set 18 CR +1 10/07/24, 10:13

    Important-104659-FileLinkHandlerResolveFile.rst:6 Reply

    Done
  67. Markus Klein commented on patch set 19 CR +1 10/07/24, 10:15

    Published edit on patch set 18.
  68. Markus Klein voted on patch set 19 CR +1 V +1 10/07/24, 10:16

  69. Markus Klein commented on patch set 19 CR 0 10/07/24, 10:16

    Important-104659-FileLinkHandlerResolveFileThrowsExceptionForInvalidFile.rst:45

    not sure about this FullyScanned. Nothing is scanned, right?
  70. Thomas Hohn commented on patch set 19 10/07/24, 10:26

    Important-104659-FileLinkHandlerResolveFileThrowsExceptionForInvalidFile.rst:45 Reply

    Will change it to NotScanned
  71. Thomas Hohn uploaded patch set 20 V +1 10/07/24, 10:27

  72. Thomas Hohn commented on patch set 20 10/07/24, 10:28

    Important-104659-FileLinkHandlerResolveFileThrowsExceptionForInvalidFile.rst:45 Reply

    Done
  73. Markus Klein voted on patch set 20 CR +1 V +1 10/07/24, 10:36

  74. core-ci voted on patch set 20 V +1 10/07/24, 10:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67226

  75. core-ci voted on patch set 18 V -1 10/07/24, 10:46 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67223

  76. core-ci voted on patch set 19 V +1 10/07/24, 10:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67224

  1. Simon Schaufelberger commented on patch set 20 10/07/24, 11:31

    Important-104659-FileLinkHandlerResolveFileThrowsExceptionForInvalidFile.rst:14

    throws a

    Important-104659-FileLinkHandlerResolveFileThrowsExceptionForInvalidFile.rst:42

    return
  2. Thomas Hohn uploaded patch set 21 CR +1 V +1 10/07/24, 11:35

  3. Thomas Hohn commented on patch set 21 10/07/24, 11:35

    Important-104659-FileLinkHandlerResolveFileThrowsExceptionForInvalidFile.rst:14 Reply

    Done

    Important-104659-FileLinkHandlerResolveFileThrowsExceptionForInvalidFile.rst:42 Reply

    Done
  4. core-ci voted on patch set 21 V +1 10/07/24, 11:52 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67230

  5. Markus Klein voted on patch set 21 CR +1 V +1 10/07/24, 12:11

  6. Simon Schaufelberger voted on patch set 21 CR +1 10/07/24, 12:29

  7. Benjamin Franzke commented on patch set 21 CR -1 10/08/24, 05:46

    `FileDoesNotExistException` is a exception that is meant to be thrown by the resource API, not as a way to structure consumers of the resource API by throwing this exception yourself. Sorry, this is -1 from my side. Returning null is just fine and can be handled easily in the calling code, otherwise an own exception would be an option as well (but `null` is better imho).
  8. Thomas Hohn uploaded patch set 22 CR +1 V +1 10/08/24, 06:23

  9. Thomas Hohn commented on patch set 22 10/08/24, 06:23

    Reply

    So changed it - hope this is better then 😊
  10. core-ci voted on patch set 22 V +1 10/08/24, 06:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67317

  11. Andreas Kienast commented on patch set 22 10/08/24, 06:28

    FileLinkHandler.php:92

    Why do we need this? We already have type declarations, this is superfluous.
  12. Thomas Hohn commented on patch set 22 10/08/24, 06:31

    FileLinkHandler.php:92 Reply

    Will remove it then ;-)
  13. Thomas Hohn uploaded patch set 23 V +1 10/08/24, 06:31

  14. Thomas Hohn commented on patch set 23 10/08/24, 06:31

    FileLinkHandler.php:92 Reply

    Done
  15. core-ci voted on patch set 23 V +1 10/08/24, 06:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67319

  16. Christian Kuhn commented on patch set 23 CR -1 10/08/24, 11:43

    on it.
  17. Christian Kuhn uploaded patch set 24 CR -1 V +1 10/08/24, 11:57

  18. Christian Kuhn uploaded patch set 25 10/08/24, 12:00

  19. Christian Kuhn commented on patch set 25 10/08/24, 12:01

    ResourceFactory.php:185

    this will be left out in v12 backport.
  20. Christian Kuhn commented on patch set 25 10/08/24, 12:01

    ResourceFactory.php:185 Reply

    Done
  21. core-ci voted on patch set 25 V +1 10/08/24, 12:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67371

  22. core-ci voted on patch set 24 V +1 10/08/24, 12:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67370

  23. Stefan Bürk voted on patch set 25 CR +1 V +1 10/08/24, 12:12

  24. Christian Kuhn voted on patch set 25 CR +2 V +2 10/08/24, 12:16

  25. Christian Kuhn merged patch set 26 10/08/24, 12:16