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

Development: Fix failing server style #9912

Merged
merged 1 commit into from
Nov 29, 2024
Merged

Conversation

SimonEntholzer
Copy link
Contributor

@SimonEntholzer SimonEntholzer commented Nov 29, 2024

Checklist

General

Server

  • I documented the Java code using JavaDoc style.

Motivation and Context

The server style checks are currently failing on develop.

Description

Fixes the failing server style checks.

Steps for Testing

Make sure the server style checks pass in the github actions below.

Review Progress

Code Review

  • Code Review 1
  • Code Review 2

@SimonEntholzer SimonEntholzer requested a review from a team as a code owner November 29, 2024 18:43
@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 29, 2024
Copy link

coderabbitai bot commented Nov 29, 2024

Walkthrough

The changes introduce two static methods, fromValue(String value), to the Kind and Level enums within the Result record. These methods facilitate the creation of enum instances from string representations, validating the input and throwing an IllegalArgumentException for invalid strings. The existing functionality of the Result record remains unchanged, with the new methods enhancing usability in string conversion scenarios.

Changes

File Path Change Summary
src/main/java/de/tum/cit/aet/artemis/programming/service/localci/scaparser/format/sarif/Result.java Added public static Kind fromValue(String value) and public static Level fromValue(String value) methods to the Kind and Level enums.

Suggested labels

code quality, ready for review, small

Suggested reviewers

  • ole-ve
  • florian-glombik

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 (7.7.0)
src/main/java/de/tum/cit/aet/artemis/programming/service/localci/scaparser/format/sarif/Result.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

@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/localci/scaparser/format/sarif/Result.java (2)

Line range hint 114-132: Enhance error handling in Kind.fromValue()

The implementation follows good practices with proper documentation and reuse of the CONSTANTS map. However, the error handling could be more robust and informative.

Consider enhancing the error handling:

 @JsonCreator
 public static Kind fromValue(String value) {
+    Objects.requireNonNull(value, "Input value cannot be null");
     Kind constant = CONSTANTS.get(value);
     if (constant == null) {
-        throw new IllegalArgumentException(value);
+        throw new IllegalArgumentException("Invalid Kind value: '" + value + "'. Expected one of: " + 
+            CONSTANTS.keySet());
     }
     return constant;
 }

Line range hint 165-183: Enhance error handling and simplify Level.fromValue()

The implementation maintains good consistency with Kind.fromValue(). However, there are opportunities for both enhanced error handling and code simplification.

Consider these improvements:

 @JsonCreator
 public static Level fromValue(String value) {
+    Objects.requireNonNull(value, "Input value cannot be null");
     Level constant = CONSTANTS.get(value);
     if (constant == null) {
-        throw new IllegalArgumentException(value);
+        throw new IllegalArgumentException("Invalid Level value: '" + value + "'. Expected one of: " + 
+            CONSTANTS.keySet());
     }
-    else {
-        return constant;
-    }
+    return constant;
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b365494 and a7c1b75.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/programming/service/localci/scaparser/format/sarif/Result.java (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/programming/service/localci/scaparser/format/sarif/Result.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

🔇 Additional comments (1)
src/main/java/de/tum/cit/aet/artemis/programming/service/localci/scaparser/format/sarif/Result.java (1)

Line range hint 114-132: Verify usage patterns and JSON deserialization

Let's verify the implementation consistency and usage patterns across the codebase.

Also applies to: 165-183

✅ Verification successful

Implementation pattern is consistent and correctly used

The Kind and Level enum implementations with @JsonCreator and fromValue methods follow a consistent pattern for JSON deserialization. The verification shows:

  1. Both enums are properly implemented with string-based mapping and null checks
  2. The pattern is used consistently within the SARIF parser context
  3. The implementation follows Jackson's best practices for enum deserialization
  4. No other similar enums in the codebase require this pattern, as these are specific to the SARIF format parsing

The implementation is correct and doesn't require any changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for similar enum patterns and usage
echo "Checking for similar enum patterns..."
ast-grep --pattern 'enum $_ {
  $$$
  @JsonCreator
  public static $_ fromValue(String value) {
    $$$
  }
}'

echo "Checking for JsonCreator usage..."
rg "@JsonCreator" -A 5

echo "Checking for potential enum value conversions..."
rg "Kind\.fromValue|Level\.fromValue"

Length of output: 4780


Script:

#!/bin/bash
# Let's check the enum definitions and their usage patterns more thoroughly

# Check the full enum definitions
echo "Checking Kind enum definition..."
rg -A 20 "enum Kind" 

echo "Checking Level enum definition..."
rg -A 20 "enum Level"

# Check for any direct usage of these enums
echo "Checking enum usage..."
rg "Kind\.|Level\." -A 2

# Check for any JSON deserialization related code
echo "Checking JSON deserialization context..."
rg "@JsonProperty.*Kind|@JsonProperty.*Level" -A 2

Length of output: 50465

Copy link
Contributor

@magaupp magaupp left a comment

Choose a reason for hiding this comment

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

Docs make sense, thanks for the fix

@krusche krusche merged commit 04ba6b9 into develop Nov 29, 2024
32 of 36 checks passed
@krusche krusche deleted the bugfix/fix-server-style-issue branch November 29, 2024 19:56
@krusche krusche added this to the 7.7.4 milestone Dec 2, 2024
AjayvirS pushed a commit that referenced this pull request Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
programming Pull requests that affect the corresponding module ready for review server Pull requests that update Java code. (Added Automatically!)
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

4 participants