Skip to content

NullReferenceException in RestaurantDetails.LoadReviews() #39

@render93

Description

@render93

Bug Description

A NullReferenceException occurs in production when a user visits the details page of a restaurant that has no reviews.

Environment

  • Environment: prod
  • Date: 2025-12-03
  • Time: 12:40:26 CET
  • Service: DevEats.Web

Error Details

Field Value
Exception Type System.NullReferenceException
Message Object reference not set to an instance of an object
Trace ID 638003fc95071eeb72d35158ec670a07

Stack Trace

System.NullReferenceException: Object reference not set to an instance of an object.
   at DevEats.Web.Pages.RestaurantDetails.LoadReviews() 
      in /home/runner/work/deveats/deveats/src/DevEats.Web/Pages/RestaurantDetails.razor:line 959
   at DevEats.Web.Pages.RestaurantDetails.LoadData() 
      in /home/runner/work/deveats/deveats/src/DevEats.Web/Pages/RestaurantDetails.razor:line 945
   at DevEats.Web.Pages.RestaurantDetails.OnInitializedAsync() 
      in /home/runner/work/deveats/deveats/src/DevEats.Web/Pages/RestaurantDetails.razor:line 927

Root Cause

The LoadReviews() method in RestaurantDetails.razor contained deliberate buggy code that was intended for Grafana testing but was deployed to production:

// DELIBERATE BUG FOR GRAFANA TESTING: Null reference when no reviews
if (!reviews.Any())
{
    Review? nullReview = null;
    var buggyAccess = nullReview.Comment; // This will throw NullReferenceException
}

When a restaurant has no reviews (e.g., Restaurant ID 10), this code attempts to access a property on a null object.

Steps to Reproduce

  1. Navigate to a restaurant detail page
  2. Select a restaurant that has no reviews (e.g., restaurant ID 10)
  3. The page crashes with NullReferenceException

Fix Applied

Removed the deliberate bug code from LoadReviews() method in src/DevEats.Web/Pages/RestaurantDetails.razor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions