From bb23e86dafc6b818b9a3f649507f8857f8e30113 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Fri, 12 Jan 2024 12:03:14 +0100 Subject: [PATCH] Fix PHP 8.1 "json_decode(null)" exception editing a form when custom field of type Users exists Summary: When `$value` is `null`, do not pass `$value` down the stack in `buildControl()` to ultimately end up with `json_decode` complaining. Instead, just skip this call. ``` EXCEPTION: (RuntimeException) json_decode(): Passing null to parameter #1 ($json) of type string is deprecated at [/src/error/PhutilErrorHandler.php:261] arcanist(head=customOAuthUrlencodeNull, ref.master=788098096e11, ref.customOAuthUrlencodeNull=4f0f2043b7e9), phorge(head=customFieldDate, ref.master=bcfcd9acfc12, ref.customFieldDate=ae8cbe84252d) #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [/src/error/PhutilErrorHandler.php:261] #1 <#2> json_decode(NULL, boolean) called at [/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php:44] #2 <#2> PhabricatorStandardCustomFieldPHIDs::setValueFromStorage(NULL) called at [/src/infrastructure/customfield/field/PhabricatorCustomField.php:895] #3 <#2> PhabricatorCustomField::setValueFromApplicationTransactions(NULL) called at [/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php:70] #4 <#2> PhabricatorCustomFieldEditField::buildControl() called at [/src/applications/transactions/editfield/PhabricatorEditField.php:385] ``` Closes T15602 Test Plan: After applying these three changes and creating a custom field with `"type": "users"` under `/config/edit/maniphest.custom-field-definitions/`, the website `/transactions/editengine/maniphest.task/view/5/` renders correctly in the browser, showing "This is a preview of the current form configuration." Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15602 Differential Revision: https://we.phorge.it/D25390 --- .../standard/PhabricatorStandardCustomFieldPHIDs.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php index 48d5ea725a..e34c3913f0 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php @@ -39,14 +39,9 @@ abstract class PhabricatorStandardCustomFieldPHIDs // should hold until this can get cleaned up more thoroughly. // TODO: Clean this up. - $result = array(); - if (!is_array($value) && phutil_nonempty_string($value)) { + if (is_string($value) && phutil_nonempty_string($value)) { $value = json_decode($value, true); - if (is_array($value)) { - $result = array_values($value); - } } - $this->setFieldValue($value); return $this;