Issue #SBCOSS-612: Resolve bug causing zero question count and API ClassCastException#215
Merged
pallakartheekreddy merged 1 commit intorelease-8.0.0from Sep 16, 2025
Merged
Conversation
- Handle multiple data types (Integer, Double, String) for `totalquestions` from the cache. - Add defensive handling for different Map implementations from the content API response. - Correct the cache key from `totalQuestions` to `totalquestions`. - Add logging for better debugging of cached content.
There was a problem hiding this comment.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Generic exception handling without context ▹ view | ||
| Redundant Map conversion logic ▹ view | ||
| Inconsistent key casing between cache and API lookup ▹ view |
Files scanned
| File Path | Reviewed |
|---|---|
| lms-jobs/assessment-aggregator/src/main/scala/org/sunbird/job/assessment/functions/AssessmentAggregatorFunction.scala | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
...gator/src/main/scala/org/sunbird/job/assessment/functions/AssessmentAggregatorFunction.scala
Show resolved
Hide resolved
...gator/src/main/scala/org/sunbird/job/assessment/functions/AssessmentAggregatorFunction.scala
Show resolved
Hide resolved
...gator/src/main/scala/org/sunbird/job/assessment/functions/AssessmentAggregatorFunction.scala
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes critical bugs in the AssessmentAggregatorFunction that were causing incorrect question count calculations and API response handling failures. The changes improve data type handling and API response parsing robustness.
- Fix question count extraction from cache to handle multiple data types (Integer, Double, Number, String) instead of defaulting to 0
- Resolve ClassCastException when parsing API responses by defensively handling different Map implementations
- Update cache key from "totalQuestions" to "totalquestions" for consistency
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...gator/src/main/scala/org/sunbird/job/assessment/functions/AssessmentAggregatorFunction.scala
Show resolved
Hide resolved
pallakartheekreddy
approved these changes
Sep 16, 2025
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.


Summary
This PR addresses a critical bug in the
AssessmentAggregatorFunctionthat caused two distinct issues:0when fetched from the cache.ClassCastExceptionwould occur when fetching assessment data from the content API.Bug Fixes and Changes
Incorrect Question Count from Cache
Problem:
The
getQuestionCountFromCachemethod was failing to parse thetotalquestionsvalue leading to a default value of0being used.Solution:
The logic has been updated to robustly handle multiple numeric types (
Integer,Double,String) that may be present in the cache, ensuring the correct question count is always retrieved also the key is changed tototalquestions.API Response
ClassCastExceptionProblem:
The
getQuestionCountFromAPImethod was throwing aClassCastExceptionbecause it did not account for the differentMapimplementations (java.util.Mapvs.scala.collection.Map) returned by the API.Solution:
The code now defensively checks the
Maptype and converts it to a standardjava.util.Map, preventing the exception and making the function more resilient.Description by Korbit AI
What change is being made?
Fix zero question count and API ClassCastException by robustly extracting totalQuestions from both cache and API responses, including case-insensitive key handling and normalization of varying map types to a common Java map.
Why are these changes being made?
Address SBCOSS-612: previously a ClassCastException and zero counts could occur due to brittle type handling and inconsistent API/cache response shapes; this change normalizes response handling and adds defensive parsing to support multiple data shapes.