Skip to content

Issue #SBCOSS-612: Resolve bug causing zero question count and API ClassCastException#215

Merged
pallakartheekreddy merged 1 commit intorelease-8.0.0from
assessment-agg-fix
Sep 16, 2025
Merged

Issue #SBCOSS-612: Resolve bug causing zero question count and API ClassCastException#215
pallakartheekreddy merged 1 commit intorelease-8.0.0from
assessment-agg-fix

Conversation

@chethann007
Copy link
Collaborator

@chethann007 chethann007 commented Sep 16, 2025

Summary

This PR addresses a critical bug in the AssessmentAggregatorFunction that caused two distinct issues:

  1. The question count was incorrectly calculated as 0 when fetched from the cache.
  2. A ClassCastException would occur when fetching assessment data from the content API.

Bug Fixes and Changes

Incorrect Question Count from Cache

  • Problem:
    The getQuestionCountFromCache method was failing to parse the totalquestions value leading to a default value of 0 being 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 to totalquestions.

API Response ClassCastException

  • Problem:
    The getQuestionCountFromAPI method was throwing a ClassCastException because it did not account for the different Map implementations (java.util.Map vs. scala.collection.Map) returned by the API.

  • Solution:
    The code now defensively checks the Map type and converts it to a standard java.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.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

- 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.
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Error Handling Generic exception handling without context ▹ view
Performance Redundant Map conversion logic ▹ view
Functionality 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.

Loving Korbit!? Share us on LinkedIn Reddit and X

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
36.4% Coverage on New Code (required ≥ 80%)
12.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pallakartheekreddy pallakartheekreddy merged commit a377ffa into release-8.0.0 Sep 16, 2025
6 of 8 checks passed
@pallakartheekreddy pallakartheekreddy deleted the assessment-agg-fix branch September 16, 2025 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants