Skip to content

Commit

Permalink
SCORM SCO-169: protect against possible NPE when accessing existing g…
Browse files Browse the repository at this point in the history
…radebook comment (sakaiproject#49)
  • Loading branch information
bjones86 authored and ern committed Apr 11, 2024
1 parent aa6566a commit c706438
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.Properties;

Expand Down Expand Up @@ -65,6 +64,7 @@
import org.sakaiproject.scorm.service.api.LearningManagementSystem;
import org.sakaiproject.scorm.service.api.ScormApplicationService;
import org.sakaiproject.scorm.service.api.ScormSequencingService;
import org.sakaiproject.service.gradebook.shared.CommentDefinition;
import org.sakaiproject.service.gradebook.shared.GradebookExternalAssessmentService;
import org.sakaiproject.service.gradebook.shared.GradebookService;
import org.sakaiproject.util.ResourceLoader;
Expand Down Expand Up @@ -1387,7 +1387,8 @@ protected void updateGradebook(OptionalDouble score, String context, String lear
{
GradebookService gbService = gradebookService();
long internalAssessmentID = gbeService.getInternalAssessmentID(context, externalAssessmentID).orElse(-1l);
String existingComment = Optional.ofNullable(gbService.getAssignmentScoreComment(context, internalAssessmentID, learnerID).getCommentText()).filter(c -> !c.isEmpty()).orElse("");
CommentDefinition cd = gbService.getAssignmentScoreComment(context, internalAssessmentID, learnerID);
String existingComment = cd != null ? StringUtils.trimToEmpty(cd.getCommentText()) : "";
String moduleNoScoreRecorded = resourceLoader.getString("moduleNoScoreRecorded");

if (score.isPresent()) // Module recorded a score...
Expand Down

0 comments on commit c706438

Please sign in to comment.