@@ -133,11 +133,30 @@ private static Student fromSQL(String[] fields) {
133133 }
134134
135135 private void fetchTasks () throws SQLException {
136- Server .getInstance ().processRequest ((t ) -> selectedTasks .add (Task .get (Integer .parseInt (t [0 ]))), "get_selected_tasks_by_student" , INTERESTING_TASKSTAT_FIELDS , String .valueOf (id ));
137- Server .getInstance ().processRequest ((t ) -> completedTasks .add (Task .get (Integer .parseInt (t [0 ]))), "get_completed_tasks_by_student" , INTERESTING_TASKSTAT_FIELDS , String .valueOf (id ));
138- Server .getInstance ().processRequest ((t ) -> lockedTasks .add (Task .get (Integer .parseInt (t [0 ]))), "get_locked_tasks_by_student" , INTERESTING_TASKSTAT_FIELDS , String .valueOf (id ));
136+ Server .getInstance ().processRequest ((t ) -> {
137+ Task task = Task .get (Integer .parseInt (t [0 ]));
138+ if (task != null ) selectedTasks .add (task );
139+ }, "get_selected_tasks_by_student" , INTERESTING_TASKSTAT_FIELDS , String .valueOf (id ));
139140
140- Server .getInstance ().processRequest ((t ) -> completedTasks .add (SpecialTask .get (Integer .parseInt (t [0 ]))), "get_completed_special_tasks_by_student" , INTERESTING_SPECIAL_TASK_STAT_FIELDS , String .valueOf (id ));
141+ Server .getInstance ().processRequest ((t ) -> {
142+ Task task = Task .get (Integer .parseInt (t [0 ]));
143+ if (task != null ) completedTasks .add (task );
144+ }, "get_completed_tasks_by_student" , INTERESTING_TASKSTAT_FIELDS , String .valueOf (id ));
145+
146+ Server .getInstance ().processRequest ((t ) -> {
147+ Task task = Task .get (Integer .parseInt (t [0 ]));
148+ if (task != null ) lockedTasks .add (task );
149+ }, "get_locked_tasks_by_student" , INTERESTING_TASKSTAT_FIELDS , String .valueOf (id ));
150+
151+ Server .getInstance ().processRequest ((t ) -> {
152+ SpecialTask st = SpecialTask .get (Integer .parseInt (t [0 ]));
153+ if (st != null ) completedTasks .add (st );
154+ }, "get_completed_special_tasks_by_student" , INTERESTING_SPECIAL_TASK_STAT_FIELDS , String .valueOf (id ));
155+
156+ // Defensive cleanup: ensure no nulls remained
157+ selectedTasks .removeIf (Objects ::isNull );
158+ completedTasks .removeIf (Objects ::isNull );
159+ lockedTasks .removeIf (Objects ::isNull );
141160 }
142161
143162 /**
@@ -358,9 +377,9 @@ public String getUsername() {
358377
359378 /**
360379 * Returns the set of locked tasks.
361- * @return completed tasks
380+ * @return locked tasks
362381 */
363- public Set <Task > getLockedTasks () { return new HashSet <>(completedTasks ); }
382+ public Set <Task > getLockedTasks () { return new HashSet <>(lockedTasks ); }
364383
365384 /**
366385 * Returns the current requests.
@@ -634,10 +653,11 @@ public Topic getCurrentTopic(Subject subject) {
634653 /**
635654 * Returns the current progress of the student for a given subject.
636655 * @param subject the subject to get the current progress for
637- * @return the current progress as a percentage (0-100 )
656+ * @return the current progress as a percentage (0-1 )
638657 */
639658 public double getCurrentProgress (Subject subject ) {
640659 return completedTasks .stream ()
660+ .filter (Objects ::nonNull )
641661 .filter (task -> task .getSubject () != null && task .getSubject ().equals (subject ))
642662 .mapToDouble (Task ::getRatio )
643663 .sum ();
0 commit comments