Skip to content

Commit

Permalink
fix possible null pointer exception and a failing Java test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Krusche committed Oct 10, 2019
1 parent de734f9 commit 28e1348
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/de/tum/in/www1/artemis/domain/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,14 @@ else if (participation.getExercise() instanceof ModelingExercise || participatio
* @param ignoreAssessmentDueDate defines if assessment due date is ignored for the selected results
* @return the latest relevant result in the given participation, or null, if none exist
*/
@Nullable
public Result findLatestRatedResultWithCompletionDate(Participation participation, Boolean ignoreAssessmentDueDate) {
// for most types of exercises => return latest result (all results are relevant)
Result latestResult = null;
// we get the results over the submissions
if (participation.getSubmissions() == null || participation.getSubmissions().isEmpty()) {
return null;
}
var results = participation.getSubmissions().stream().map(Submission::getResult).filter(Objects::nonNull).collect(Collectors.toSet());
for (Result result : results) {
// NOTE: for the dashboard we only use rated results with completion date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.*;
import java.util.stream.Collectors;

import javax.annotation.Nullable;
import javax.persistence.*;

import org.hibernate.Hibernate;
Expand Down Expand Up @@ -444,6 +445,7 @@ public StudentParticipation findRelevantParticipation(List<StudentParticipation>
}

@Override
@Nullable
public Result findLatestRatedResultWithCompletionDate(Participation participation, Boolean ignoreAssessmentDueDate) {
if (shouldFilterForStudents()) {
// results are never relevant before quiz has ended => return null
Expand All @@ -452,6 +454,9 @@ public Result findLatestRatedResultWithCompletionDate(Participation participatio
else {
// only rated results are considered relevant
Result latestRatedResult = null;
if (participation.getSubmissions() == null || participation.getSubmissions().isEmpty()) {
return null;
}
// we get the results over the submissions
var results = participation.getSubmissions().stream().map(Submission::getResult).filter(Objects::nonNull).collect(Collectors.toSet());
for (Result result : results) {
Expand Down

0 comments on commit 28e1348

Please sign in to comment.