New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instructor: view results: fix IndexOutOfBoundsException #8415 #8714
Instructor: view results: fix IndexOutOfBoundsException #8415 #8714
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we completely remove numOfMsqChoices
?
optionListHtml.append("<ul style=\"list-style-type: disc;margin-left: 20px;\" >"); | ||
for (int i = 0; i < numOfMsqChoices; i++) { | ||
for (int i = 0; i < msqChoices.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (String msqChoice : msqChoices.size() {
If we're not removing teammates/src/main/java/teammates/common/datatransfer/questions/FeedbackMsqQuestionDetails.java Lines 120 to 128 in cd9a536
Here, If we are removing |
@@ -479,9 +479,9 @@ public String getQuestionAdditionalInfoHtml(int questionNumber, String additiona | |||
optionListHtml.append(optionHelpText); | |||
} | |||
|
|||
if (numOfMsqChoices > 0) { | |||
if (!msqChoices.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I feel that for clarity, this whole block should be an else-if of the if statement just above. It should only run for non-generated options.
2 possible ways to go from here:
teammates/src/main/java/teammates/common/datatransfer/questions/FeedbackMsqQuestionDetails.java Lines 598 to 599 in cd9a536
For data migration, I'm not exactly sure of the consequences of that, or how much work it could take. @whipermr5 do you have any recommendations on this?
I think |
Also, just curious if there is any tangible negative impact of the inconsistency in the database? Because if we manage it well, it seems fine (or maybe not haha but I'm interested to know the reason). |
I tried the approach of storing the entire studentList/teamList/instructorList in I created a msq with generated options and saved the question. But as you can see from the ss below, the choices will be populated with the entire class list, and that's not what we want. I guess this is why the Since this way doesn't seem to work, and we need a field to store the number of msqChoices for |
I think we can keep |
@whipermr5 But if we make |
@Haozhe321 I believe validation is only supposed to be done before a question is persisted to the datastore? Anyway auto-generated options are never supposed to be persisted; they should be generated when accessed as the options can change (e.g. if the student list changes). |
Validation is also done when editing a question i.e. changing the maximum/minimum number of choices, which requires retrieving information of the question from the datastore.
I see, that makes sense. Then another way to validate is to use |
I think this issue is described in #8646, where we cant have meaningful backend validation for questions (for responses too). |
cfbc4f8
to
b4e3dcf
Compare
@whipermr5 here are the changes made:
So now the field The 2nd error that PMD flagged out is "Confusing Ternary", which should be skipped when confusing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint errors
@whipermr5 I'm aware of the lint errors. Need your opinions on them:
Other than the lint errors, the CI tests have passed on my local machine. |
@Haozhe321 Oops didn't read your previous comment carefully 😅 You can always add suppression annotations for now. |
@Haozhe321 @whipermr5 I'm currently looking at re-organizing the PMD rules. Consider the request for adding |
9b0803a
to
d6e2e89
Compare
@whipermr5 fixed the style issues. |
@@ -30,7 +30,7 @@ | |||
import teammates.ui.template.InstructorFeedbackResultsResponseRow; | |||
|
|||
public class FeedbackMsqQuestionDetails extends FeedbackQuestionDetails { | |||
private int numOfMsqChoices; | |||
private transient int numOfMsqChoices; //NOPMD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suppress the specific rule and add a comment? E.g.
teammates/src/main/java/teammates/storage/entity/FeedbackSession.java
Lines 28 to 32 in e32eeff
// PMD.UnusedPrivateField and SingularField are suppressed | |
// as feedbackSessionId is persisted to the database | |
@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) | |
@Id | |
private transient String feedbackSessionId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
…son for generated options
Change method name, method visibility, and method parameter name for getNumOfChoicesForMsq in FeedbackMsqQuestionDetails. Removed the method getNumOfMsqChoices(). Replaced getRequestParamValue with getNonNullRequestParamValue for editQuestion() method in InstructorFeedbackQuestionEditAction.
c3f2928
to
b1f7dae
Compare
@whipermr5 changes made! |
@@ -347,12 +347,10 @@ public int getNumOfChoicesForMsq(String courseId, FeedbackParticipantType genera | |||
} catch (EntityDoesNotExistException e) { | |||
Assumption.fail("Course disappeared"); | |||
} | |||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do it for the whole method - there should be no else ifs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I misunderstood what you meant. Do you mean the following?
public int getNumOfChoicesForMsq(String courseId, FeedbackParticipantType generateOptionsFor) {
if (generateOptionsFor == FeedbackParticipantType.NONE) {
return msqChoices.size();
}
if (generateOptionsFor == FeedbackParticipantType.STUDENTS
|| generateOptionsFor == FeedbackParticipantType.STUDENTS_EXCLUDING_SELF) {
List<StudentAttributes> studentList = StudentsLogic.inst().getStudentsForCourse(courseId);
int sizeOfStudentlist = studentList.size();
return generateOptionsFor == FeedbackParticipantType.STUDENTS ? sizeOfStudentlist : sizeOfStudentlist - 1;
}
if (generateOptionsFor == FeedbackParticipantType.TEAMS
|| generateOptionsFor == FeedbackParticipantType.TEAMS_EXCLUDING_SELF) {
try {
List<TeamDetailsBundle> teamList = CoursesLogic.inst().getTeamsForCourse(courseId);
int sizeOfTeamlist = teamList.size();
return generateOptionsFor == FeedbackParticipantType.TEAMS ? sizeOfTeamlist : sizeOfTeamlist - 1;
} catch (EntityDoesNotExistException e) {
Assumption.fail("Course disappeared");
}
}
List<InstructorAttributes> instructorList = InstructorsLogic.inst().getInstructorsForCourse(courseId);
return instructorList.size();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've push up the changes. What's the difference between this version and the previous version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 It just looks slightly neater I think
b1f7dae
to
1030ee7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Fixes #8415
Outline of Solution
msqChoices
list will be used to determine the logic for the loop so there will not be a discrepancy between the number of choices and the choices themselves.@craaaa