XF 2.3 ErrorException: [E_WARNING] Attempt to read property "thread_id" on null in src/

Abraham54

Well-known member
Licensed customer
My forum had strange faults so I made a new install and imported my forum.
The import went wellbut after finalizing I get this warning:

ErrorException: [E_WARNING] Attempt to read property "thread_id" on null in src/XF/ThreadType/QuestionHandler.php at line 498

  1. XF::handlePhpError() in src/XF/ThreadType/QuestionHandler.php at line 498
  2. XF\ThreadType\QuestionHandler->onThreadRebuildCounters() in src/XF/Entity/Thread.php at line 882
  3. XF\Entity\Thread->rebuildCounters() in src/XF/Job/Thread.php at line 37
  4. XF\Job\Thread->rebuildById() in src/XF/Job/AbstractRebuildJob.php at line 65
  5. XF\Job\AbstractRebuildJob->run() in src/XF/Job/Atomic.php at line 40
  6. XF\Job\Atomic->run() in src/XF/Job/Manager.php at line 275
  7. XF\Job\Manager->runJobInternal() in src/XF/Job/Manager.php at line 205
  8. XF\Job\Manager->runJobEntry() in src/XF/Job/Manager.php at line 121
  9. XF\Job\Manager->runByIds() in src/XF/Admin/Controller/ToolsController.php at line 146
  10. XF\Admin\Controller\ToolsController->actionRunJob() in src/XF/Mvc/Dispatcher.php at line 364
  11. XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 266
  12. XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 121
  13. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 63
  14. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2840
  15. XF\App->run() in src/XF.php at line 850
  16. XF::runApp() in admin.php at line 15

  • ErrorException: [E_WARNING] Attempt to read property "thread_id" on null
  • src/XF/ThreadType/QuestionHandler.php:498
  • Gegenereerd door: Abraham545
  • 20 nov 2026 om 12:08
Stack trace
#0 src/XF/ThreadType/QuestionHandler.php(498): XF::handlePhpError(2, '[E_WARNING] Att...', '/home/u46315p56...', 498)
#1 src/XF/Entity/Thread.php(882): XF\ThreadType\QuestionHandler->onThreadRebuildCounters(Object(XF\Entity\Thread))
#2 src/XF/Job/Thread.php(37): XF\Entity\Thread->rebuildCounters()
#3 src/XF/Job/AbstractRebuildJob.php(65): XF\Job\Thread->rebuildById(13984)
#4 src/XF/Job/Atomic.php(40): XF\Job\AbstractRebuildJob->run(8)
#5 src/XF/Job/Manager.php(275): XF\Job\Atomic->run(8)
#6 src/XF/Job/Manager.php(205): XF\Job\Manager->runJobInternal(Array, 8)
#7 src/XF/Job/Manager.php(121): XF\Job\Manager->runJobEntry(Array, 8)
#8 src/XF/Admin/Controller/ToolsController.php(146): XF\Job\Manager->runByIds(Array, 8)
#9 src/XF/Mvc/Dispatcher.php(364): XF\Admin\Controller\ToolsController->actionRunJob(Object(XF\Mvc\ParameterBag))
#10 src/XF/Mvc/Dispatcher.php(266): XF\Mvc\Dispatcher->dispatchClass('XF:Tools', 'RunJob', Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\ToolsController), NULL)
#11 src/XF/Mvc/Dispatcher.php(121): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\ToolsController), NULL)
#12 src/XF/Mvc/Dispatcher.php(63): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#13 src/XF/App.php(2840): XF\Mvc\Dispatcher->run()
#14 src/XF.php(850): XF\App->run()
#15 admin.php(15): XF::runApp('XF\\Admin\\App')
#16 {main}

Aanvraagstatus​


array(4) {
["url"] => string(24) "/admin.php?tools/run-job"
["referrer"] => string(47) "https://piepcomptest.nl/admin.php?tools/run-job"
["_GET"] => array(1) {
["tools/run-job"] => string(0) ""
}
["_POST"] => array(3) {
["_xfRedirect"] => string(49) "https://piepcomptest.nl/admin.php?import/finalize"
["_xfToken"] => string(8) "********"
["only_ids"] => string(4) "1015"
}
}

How to solve this?
 
My forum had strange faults so I made a new install and imported my forum.
The import went wellbut after finalizing I get this warning:

ErrorException: [E_WARNING] Attempt to read property "thread_id" on null in src/XF/ThreadType/QuestionHandler.php at line 498

  1. XF::handlePhpError() in src/XF/ThreadType/QuestionHandler.php at line 498
  2. XF\ThreadType\QuestionHandler->onThreadRebuildCounters() in src/XF/Entity/Thread.php at line 882
  3. XF\Entity\Thread->rebuildCounters() in src/XF/Job/Thread.php at line 37
  4. XF\Job\Thread->rebuildById() in src/XF/Job/AbstractRebuildJob.php at line 65
  5. XF\Job\AbstractRebuildJob->run() in src/XF/Job/Atomic.php at line 40
  6. XF\Job\Atomic->run() in src/XF/Job/Manager.php at line 275
  7. XF\Job\Manager->runJobInternal() in src/XF/Job/Manager.php at line 205
  8. XF\Job\Manager->runJobEntry() in src/XF/Job/Manager.php at line 121
  9. XF\Job\Manager->runByIds() in src/XF/Admin/Controller/ToolsController.php at line 146
  10. XF\Admin\Controller\ToolsController->actionRunJob() in src/XF/Mvc/Dispatcher.php at line 364
  11. XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 266
  12. XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 121
  13. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 63
  14. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2840
  15. XF\App->run() in src/XF.php at line 850
  16. XF::runApp() in admin.php at line 15

  • ErrorException: [E_WARNING] Attempt to read property "thread_id" on null
  • src/XF/ThreadType/QuestionHandler.php:498
  • Gegenereerd door: Abraham545
  • 20 nov 2026 om 12:08
Stack trace
#0 src/XF/ThreadType/QuestionHandler.php(498): XF::handlePhpError(2, '[E_WARNING] Att...', '/home/u46315p56...', 498)
#1 src/XF/Entity/Thread.php(882): XF\ThreadType\QuestionHandler->onThreadRebuildCounters(Object(XF\Entity\Thread))
#2 src/XF/Job/Thread.php(37): XF\Entity\Thread->rebuildCounters()
#3 src/XF/Job/AbstractRebuildJob.php(65): XF\Job\Thread->rebuildById(13984)
#4 src/XF/Job/Atomic.php(40): XF\Job\AbstractRebuildJob->run(8)
#5 src/XF/Job/Manager.php(275): XF\Job\Atomic->run(8)
#6 src/XF/Job/Manager.php(205): XF\Job\Manager->runJobInternal(Array, 8)
#7 src/XF/Job/Manager.php(121): XF\Job\Manager->runJobEntry(Array, 8)
#8 src/XF/Admin/Controller/ToolsController.php(146): XF\Job\Manager->runByIds(Array, 8)
#9 src/XF/Mvc/Dispatcher.php(364): XF\Admin\Controller\ToolsController->actionRunJob(Object(XF\Mvc\ParameterBag))
#10 src/XF/Mvc/Dispatcher.php(266): XF\Mvc\Dispatcher->dispatchClass('XF:Tools', 'RunJob', Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\ToolsController), NULL)
#11 src/XF/Mvc/Dispatcher.php(121): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\ToolsController), NULL)
#12 src/XF/Mvc/Dispatcher.php(63): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#13 src/XF/App.php(2840): XF\Mvc\Dispatcher->run()
#14 src/XF.php(850): XF\App->run()
#15 admin.php(15): XF::runApp('XF\\Admin\\App')
#16 {main}

Aanvraagstatus​


array(4) {
["url"] => string(24) "/admin.php?tools/run-job"
["referrer"] => string(47) "https://piepcomptest.nl/admin.php?tools/run-job"
["_GET"] => array(1) {
["tools/run-job"] => string(0) ""
}
["_POST"] => array(3) {
["_xfRedirect"] => string(49) "https://piepcomptest.nl/admin.php?import/finalize"
["_xfToken"] => string(8) "********"
["only_ids"] => string(4) "1015"
}
}

How to solve this?
Hi Abraham54,

The rebuild runs fine until it reaches thread 13984. That's a question thread, and its stored data still points to a "solution" post that doesn't exist on the new install (probably deleted on the old forum, or its ID didn't carry over through the import). At line 498, QuestionHandler::onThreadRebuildCounters() loads that post and reads its thread ID without checking that the post was found, so the PHP warning stops the job.

1. Let XenForo clean them up itself. Back up your database and the file first, then in src/XF/ThreadType/QuestionHandler.php change line 498 from:

PHP:
if ($post->thread_id != $thread->thread_id || $post->message_state != 'visible')

to:

PHP:
if (!$post || $post->thread_id != $thread->thread_id || $post->message_state != 'visible')

Then run Admin CP > Tools > Rebuild caches > Rebuild threads. With that check in place, a missing solution post is handled like a solution sitting in the wrong thread: XenForo removes the "solution" mark from the thread and the rebuild goes through, for 13984 and any other thread in the same state.

2. Put the original file back once the rebuild has finished. The broken references are gone by then, so the original line won't hit a missing post anymore. Restoring it also keeps the File health check clean (and the next upgrade would overwrite it anyway).

The only thing you lose is the "solution" mark on those threads. If one of them really matters, you can mark the right answer again by hand.

This one is worth a report in the Bugs forum too: the core should check for a missing post there, like it already does for a solution in the wrong thread.
 
@SenseiXS Many thanks for your solution, I removed the tread in the database.
Strange enough, this message could not be found when I searched for this message.
Glad it's sorted! The fact that you couldn't find it fits: the thread was pointing to a "solution" post that no longer existed, which is exactly what broke the rebuild.

One thing to keep in mind: deleting a thread straight from the database only removes that one row. Its posts and related data stay behind, and your forum and user counts still include them. To tidy up, go to Admin CP > Tools > Rebuild caches and run:

  • Rebuild threads, all the way to the end. If it finishes without the warning, no other thread had the same problem. If it stops on another thread, that one is in the same state, and the code change from my first reply fixes all of them in one go.
  • Rebuild forums
  • Rebuild message counts
  • Rebuild search index, if that thread used to show up in search results.

Next time, delete the thread from the front end instead (Thread tools > Delete thread > Permanently delete): XenForo then cleans up the posts and counters along with it.
 
@SenseiXS I also always rebuild everything after an import.

By the way, it was for me the first time to get an error message by finalizing the import.
That makes sense. When a post marked as a solution is deleted the normal way, XenForo also removes the mark from the thread, so this situation shouldn't happen on its own. For a thread to point to a missing post, that post must have disappeared outside XenForo's normal flow (a direct database edit, an add-on, a delete interrupted halfway). That fits the strange faults you had on the old forum: the import just carried the broken reference over, and the rebuild was the first thing to trip on it.

So the problem came from the old data, not from your new install. If the same warning ever comes back, it'll be another leftover of the same kind.
 
Back
Top Bottom