Fix division by zero exception in OwnerController.showOwner()#471
Open
doppleware wants to merge 2 commits intomainfrom
Open
Fix division by zero exception in OwnerController.showOwner()#471doppleware wants to merge 2 commits intomainfrom
doppleware wants to merge 2 commits intomainfrom
Conversation
Add null check and guard clause to prevent division by zero when owner has no pets, defaulting petFactor to 1 when pets list is empty or null
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the division by zero exception that occurs in the
OwnerController.showOwner()method at line 180 when an owner has no pets.Root Cause
The problematic line
int petFactor = 1 / owner.getPets().size();attempts to divide by zero whenowner.getPets().size()returns 0, which happens when an owner has no pets.Solution
Added a guard check before the division operation to handle the case when the pet list is empty. If
owner.getPets()is null or empty (size == 0),petFactoris set to a safe default value of 1.Error Details
Testing
This fix should resolve the ArithmeticException when accessing owner profiles with no pets. Monitor error ID 555222fc-ca6d-11f0-af58-22f2dd697fbe in the Digma environment to confirm resolution.