Skip to content
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

Programming exercises: Fix an issue for grading statistics #9779

Merged

Conversation

az108
Copy link
Contributor

@az108 az108 commented Nov 14, 2024

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) and too complex database calls.
  • I strictly followed the principle of data economy for all database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).
  • I added pre-authorization annotations according to the guidelines and checked the course groups for all new REST Calls (security).
  • I documented the Java code using JavaDoc style.

Motivation and Context

A NullPointerException appeared in the server logs while loading grading statistics.

Description

My assumption is that because feedback.isPositive can be null (in cases where the test case has not run for the submission yet, possibly due to hidden tests), the grading statistics cannot distinguish this scenario. In my opinion, this can be ignored in the statistics and should not be considered, as after the deadline, once all test cases have run, the feedback for students should have a definitive isPositive value.

Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling for feedback processing to prevent null-related errors.
    • Added logging for potential issues, improving diagnostics for debugging.
  • Improvements

    • Expanded filtering logic for feedback to ensure better reliability and robustness.

@az108 az108 added the bugfix label Nov 14, 2024
@az108 az108 self-assigned this Nov 14, 2024
@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) programming Pull requests that affect the corresponding module labels Nov 14, 2024
@az108 az108 marked this pull request as ready for review November 14, 2024 17:30
@az108 az108 requested a review from a team as a code owner November 14, 2024 17:30
…-testCaseMap-null-value' into bugfix/programming-exercises/fix-testCaseMap-null-value
Copy link

coderabbitai bot commented Nov 14, 2024

Walkthrough

The ProgrammingExerciseGradingService class has been modified to enhance error handling and logging in the updateTestCaseMapBasedOnResultFeedback method. The updates include additional checks for null values in feedback-related data, specifically ensuring that the test case and its name are not null. Warnings are logged if these checks fail, along with a check for the isPositive attribute of the feedback. These changes aim to improve the reliability of feedback processing by addressing potential null-related errors.

Changes

File Path Change Summary
src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingExerciseGradingService.java Enhanced error handling and logging in updateTestCaseMapBasedOnResultFeedback method; added null checks for feedback and test case attributes, with corresponding warnings logged.

Possibly related PRs

Suggested labels

tests, assessment

Suggested reviewers

  • b-fein
  • krusche
  • Jan-Thurner

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 pmd
src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingExerciseGradingService.java

The following rules are missing or misspelled in your ruleset file category/vm/bestpractices.xml: BooleanInstantiation, DontImportJavaLang, DuplicateImports, EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, EmptyStatementNotInLoop, EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, EmptyWhileStmt, ExcessiveClassLength, ExcessiveMethodLength, ImportFromSamePackage, MissingBreakInSwitch, SimplifyBooleanAssertion. Please check your ruleset configuration.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@raffifasaro raffifasaro left a comment

Choose a reason for hiding this comment

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

Code LGTM

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingExerciseGradingService.java (2)

1081-1099: LGTM! Consider enhancing the warning logs.

The null checks effectively prevent NullPointerException. However, the warning logs could include more context about the feedback to aid debugging.

Consider enhancing the warning logs:

-log.warn("Feedback with ID {} has a test case with a null test name.", feedback.getId());
+log.warn("Feedback with ID {} has a test case with a null test name. Exercise: {}, Participation: {}", 
+    feedback.getId(), feedback.getResult().getParticipation().getExercise().getId(),
+    feedback.getResult().getParticipation().getId());

-log.warn("Feedback with ID {} has a test case with a null isPositive value.", feedback.getId());
+log.warn("Feedback with ID {} has a test case with a null isPositive value. Exercise: {}, Participation: {}", 
+    feedback.getId(), feedback.getResult().getParticipation().getExercise().getId(),
+    feedback.getResult().getParticipation().getId());

1081-1099: Consider extracting filter conditions for better readability.

The filter conditions could be more readable if extracted into a separate method.

Consider this refactoring:

-result.getFeedbacks().stream()
-    .filter(feedback -> {
-        if (!FeedbackType.AUTOMATIC.equals(feedback.getType())) {
-            return false;
-        }
-        if (feedback.getTestCase() == null) {
-            return false;
-        }
-        if (feedback.getTestCase().getTestName() == null) {
-            log.warn("Feedback with ID {} has a test case with a null test name.", feedback.getId());
-            return false;
-        }
-        if (feedback.isPositive() == null) {
-            log.warn("Feedback with ID {} has a test case with a null isPositive value.", feedback.getId());
-            return false;
-        }
-        return true;
-    })
+result.getFeedbacks().stream()
+    .filter(this::isValidTestCaseFeedback)

+/**
+ * Checks if the feedback is valid for test case statistics.
+ * A valid feedback must:
+ * - Be of type AUTOMATIC
+ * - Have a non-null test case with a non-null test name
+ * - Have a non-null isPositive value
+ *
+ * @param feedback The feedback to validate
+ * @return true if the feedback is valid, false otherwise
+ */
+private boolean isValidTestCaseFeedback(Feedback feedback) {
+    if (!FeedbackType.AUTOMATIC.equals(feedback.getType())) {
+        return false;
+    }
+    if (feedback.getTestCase() == null) {
+        return false;
+    }
+    if (feedback.getTestCase().getTestName() == null) {
+        log.warn("Feedback with ID {} has a test case with a null test name.", feedback.getId());
+        return false;
+    }
+    if (feedback.isPositive() == null) {
+        log.warn("Feedback with ID {} has a test case with a null isPositive value.", feedback.getId());
+        return false;
+    }
+    return true;
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d266ee6 and b162580.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingExerciseGradingService.java (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingExerciseGradingService.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

@az108 az108 added this to the 7.7.1 milestone Nov 14, 2024
Copy link
Member

@BBesrour BBesrour left a comment

Choose a reason for hiding this comment

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

code lgtm

@krusche krusche changed the title Programming exercises: Resolve null feedback issue in testcase map for grading statistics Programming exercises: Fix an issue for grading statistics Nov 15, 2024
@krusche krusche merged commit c1bfa2f into develop Nov 15, 2024
41 of 44 checks passed
@krusche krusche deleted the bugfix/programming-exercises/fix-testCaseMap-null-value branch November 15, 2024 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix programming Pull requests that affect the corresponding module ready to merge server Pull requests that update Java code. (Added Automatically!)
Projects
Archived in project
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants