Page MenuHomePhabricator

PHP Deprecated: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
labels.normalized_message
[{reqId}] {exception_url}   PHP Deprecated: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated
FrameLocationCall
from/srv/mediawiki/php-1.44.0-wmf.13/extensions/UploadWizard/includes/FlickrBlacklist.php(147)
#0[internal function]MWExceptionHandler::handleError(int, string, string, int)
#1/srv/mediawiki/php-1.44.0-wmf.13/extensions/UploadWizard/includes/FlickrBlacklist.php(147)json_decode(null, bool)
#2/srv/mediawiki/php-1.44.0-wmf.13/extensions/UploadWizard/includes/FlickrBlacklist.php(80)MediaWiki\Extension\UploadWizard\FlickrBlacklist->getUserIdsFromPhotoId(string)
#3/srv/mediawiki/php-1.44.0-wmf.13/extensions/UploadWizard/includes/Hooks.php(157)MediaWiki\Extension\UploadWizard\FlickrBlacklist->isBlacklisted(string)
#4/srv/mediawiki/php-1.44.0-wmf.13/includes/HookContainer/HookContainer.php(155)MediaWiki\Extension\UploadWizard\Hooks->onIsUploadAllowedFromUrl(string, bool)
#5/srv/mediawiki/php-1.44.0-wmf.13/includes/HookContainer/HookRunner.php(2300)MediaWiki\HookContainer\HookContainer->run(string, array)
#6/srv/mediawiki/php-1.44.0-wmf.13/includes/upload/UploadFromUrl.php(200)MediaWiki\HookContainer\HookRunner->onIsUploadAllowedFromUrl(string, bool)
#7/srv/mediawiki/php-1.44.0-wmf.13/includes/api/ApiUpload.php(757)UploadFromUrl::isAllowedUrl(string)
#8/srv/mediawiki/php-1.44.0-wmf.13/includes/api/ApiUpload.php(125)MediaWiki\Api\ApiUpload->selectUploadModule()
#9/srv/mediawiki/php-1.44.0-wmf.13/includes/api/ApiMain.php(1973)MediaWiki\Api\ApiUpload->execute()
#10/srv/mediawiki/php-1.44.0-wmf.13/includes/api/ApiMain.php(941)MediaWiki\Api\ApiMain->executeAction()
#11/srv/mediawiki/php-1.44.0-wmf.13/includes/api/ApiMain.php(912)MediaWiki\Api\ApiMain->executeActionWithErrorHandling()
#12/srv/mediawiki/php-1.44.0-wmf.13/includes/api/ApiEntryPoint.php(152)MediaWiki\Api\ApiMain->execute()
#13/srv/mediawiki/php-1.44.0-wmf.13/includes/MediaWikiEntryPoint.php(202)MediaWiki\Api\ApiEntryPoint->execute()
#14/srv/mediawiki/php-1.44.0-wmf.13/api.php(44)MediaWiki\MediaWikiEntryPoint->run()
#15/srv/mediawiki/w/api.php(3)require(string)
#16{main}
Impact
Notes

Event Timeline

The code from 2013 is:

includes/FlickrBlacklist.php
$response = MediaWikiServices::getInstance()->getHttpRequestFactory()
    ->post( $this->flickrApiUrl, $params, __METHOD__ );
if ( $response !== false ) {
    $response = json_decode( $response, true );
}

But post() is documented to return string|null, same for the underlying request(). I imagine ideally Phan should catch that we compare a string|null with boolean false and should flag it.

The reason is 4e9cd14878149ce59138767c02458ea4dea87ac4 by @Umherirrender. The patch switches to HttpRequestFactory::post which returns string|null when previously it used Http:post which returned string|false false on error.

Change #1115338 had a related patch set uploaded (by Hashar; author: Hashar):

[mediawiki/extensions/UploadWizard@master] Fix response error handling in FlickrBlacklist

https://gerrit.wikimedia.org/r/1115338

Change #1115338 merged by jenkins-bot:

[mediawiki/extensions/UploadWizard@master] Fix response error handling in FlickrBlacklist

https://gerrit.wikimedia.org/r/1115338

Change #1115344 had a related patch set uploaded (by Hashar; author: Hashar):

[mediawiki/extensions/UploadWizard@wmf/1.44.0-wmf.14] Fix response error handling in FlickrBlacklist

https://gerrit.wikimedia.org/r/1115344

Change #1115346 had a related patch set uploaded (by Hashar; author: Hashar):

[mediawiki/extensions/UploadWizard@REL1_39] Fix response error handling in FlickrBlacklist

https://gerrit.wikimedia.org/r/1115346

Change #1115346 abandoned by Hashar:

[mediawiki/extensions/UploadWizard@REL1_39] Fix response error handling in FlickrBlacklist

https://gerrit.wikimedia.org/r/1115346

Change #1115347 had a related patch set uploaded (by Hashar; author: Hashar):

[mediawiki/extensions/UploadWizard@REL1_42] Fix response error handling in FlickrBlacklist

https://gerrit.wikimedia.org/r/1115347

Change #1115348 had a related patch set uploaded (by Hashar; author: Hashar):

[mediawiki/extensions/UploadWizard@REL1_43] Fix response error handling in FlickrBlacklist

https://gerrit.wikimedia.org/r/1115348

Change #1115346 restored by Hashar:

[mediawiki/extensions/UploadWizard@REL1_39] Fix response error handling in FlickrBlacklist

https://gerrit.wikimedia.org/r/1115346

Change #1115344 merged by jenkins-bot:

[mediawiki/extensions/UploadWizard@wmf/1.44.0-wmf.14] Fix response error handling in FlickrBlacklist

https://gerrit.wikimedia.org/r/1115344

Mentioned in SAL (#wikimedia-operations) [2025-01-30T13:24:54Z] <hashar@deploy2002> Started scap sync-world: Backport for [[gerrit:1115344|Fix response error handling in FlickrBlacklist (T385143)]]

Mentioned in SAL (#wikimedia-operations) [2025-01-30T13:27:58Z] <hashar@deploy2002> hashar: Backport for [[gerrit:1115344|Fix response error handling in FlickrBlacklist (T385143)]] synced to the testservers (https://wikitech.wikimedia.org/wiki/Mwdebug)

Mentioned in SAL (#wikimedia-operations) [2025-01-30T13:36:49Z] <hashar@deploy2002> Finished scap sync-world: Backport for [[gerrit:1115344|Fix response error handling in FlickrBlacklist (T385143)]] (duration: 11m 54s)

Change #1115346 merged by jenkins-bot:

[mediawiki/extensions/UploadWizard@REL1_39] Fix response error handling in FlickrBlacklist

https://gerrit.wikimedia.org/r/1115346

Change #1115347 merged by jenkins-bot:

[mediawiki/extensions/UploadWizard@REL1_42] Fix response error handling in FlickrBlacklist

https://gerrit.wikimedia.org/r/1115347

Change #1115348 merged by jenkins-bot:

[mediawiki/extensions/UploadWizard@REL1_43] Fix response error handling in FlickrBlacklist

https://gerrit.wikimedia.org/r/1115348

But post() is documented to return string|null, same for the underlying request(). I imagine ideally Phan should catch that we compare a string|null with boolean false and should flag it.

It does, but only if the return type is typehinted. Impossible comparisons (like this one where a string|null value is compared against false) are only reported for "real" types, i.e., those that are enforced by the interpreter or other runtime checks (typehints, if ( cond ), assert( cond ), etc.). Phan's philosophy is to avoid false positives, and docblock types in legacy code are notoriously inaccurate when it comes to small details (like null vs false vs empty string vs 0).

Reedy removed a project: Patch-For-Review.

Thank you, meanwhile I filed a task dedicated to Phan and I pasted your above response there: T385200