Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Paurikova2
Copy link
Collaborator

@Paurikova2 Paurikova2 commented Apr 16, 2025

Phases MP MM MB MR JM Total
ETA 0 0 0 0 0 0
Developing 1 0 0 0 0 0
Review 0 0 0 0 0 0
Total - - - - - 0
ETA est. 0
ETA cust. - - - - - 0

Problem description

The endpoints: ..server/api/core/clarinlruallowances/330/userMetadata(userRegistration) throw nullpoint exception.

Summary by CodeRabbit

  • Bug Fixes
    • Improved authorization checks to prevent errors when the current user is not set.
    • Enhanced error handling by converting authorization exceptions into REST-specific exceptions for better API consistency.

@coderabbitai
Copy link

coderabbitai bot commented Apr 16, 2025

Walkthrough

A null check for the currentUser object was introduced in the authorizeClruaAction method within the ClarinLicenseResourceUserAllowanceServiceImpl class. This update ensures that the code verifies the existence of currentUser before attempting to access its ID, thereby preventing possible NullPointerException occurrences during authorization checks. Additionally, two repository classes, CLRUAUUserRegistrationLinkRepository and CLRUAUserMetadataLinkRepository, were updated to catch AuthorizeException and rethrow it as RESTAuthorizationException, changing their method signatures accordingly to reflect the new exception type.

Changes

File Path Change Summary
dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseResourceUserAllowanceServiceImpl.java Added a null check for currentUser in the authorizeClruaAction method to prevent null dereference errors.
dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/CLRUAUUserRegistrationLinkRepository.java
dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/CLRUAUserMetadataLinkRepository.java
Wrapped calls to clarinLicenseResourceUserAllowanceService.find in try-catch blocks to catch AuthorizeException and rethrow as RESTAuthorizationException. Updated method signatures to remove AuthorizeException and declare RESTAuthorizationException instead.

Poem

A bunny hopped through fields of code,
And found a place where nulls abode.
With careful paws, it checked each one,
So errors now are nearly none.
No NullPointer shall cause dismay—
Just happy hops and safer play! 🐇

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this 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 anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@Paurikova2 Paurikova2 self-assigned this Apr 16, 2025
@Paurikova2 Paurikova2 linked an issue Apr 16, 2025 that may be closed by this pull request
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

🧹 Nitpick comments (2)
dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/CLRUAUserMetadataLinkRepository.java (2)

57-58: Minor typo in error message.

There's a typo in the error message: "for if: " should be "for id: " to match the error message pattern used in other similar locations.

-            throw new ResourceNotFoundException("The ClarinLicenseResourceUserAllowance for if: " + clruaID +
+            throw new ResourceNotFoundException("The ClarinLicenseResourceUserAllowance for id: " + clruaID +
                    " couldn't be found");

62-65: Minor spacing issue in error message.

There's a missing space between "clruaID" and "doesn't" in the error message, which would cause the error message to display without proper spacing.

-                    "with id: " + clruaID + "doesn't exists.");
+                    "with id: " + clruaID + " doesn't exist.");

Additionally, grammatically, "doesn't exists" should be "doesn't exist".

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0545e7a and c782ca1.

📒 Files selected for processing (2)
  • dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/CLRUAUUserRegistrationLinkRepository.java (2 hunks)
  • dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/CLRUAUserMetadataLinkRepository.java (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: dspace-dependencies / docker-build (linux/amd64, ubuntu-latest, true)
  • GitHub Check: Run Integration Tests
  • GitHub Check: Run Unit Tests
🔇 Additional comments (6)
dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/CLRUAUUserRegistrationLinkRepository.java (3)

15-15: Import added for exception handling improvement.

The import of org.dspace.app.rest.exception.RESTAuthorizationException has been added to support the changes in exception handling.


43-44: Method signature updated to reflect exception handling changes.

The method signature has been modified to replace AuthorizeException with RESTAuthorizationException. This change aligns the method signature with the updated exception handling approach.


47-52: Improved exception handling to prevent null pointer exceptions.

The code now properly catches AuthorizeException thrown by the service layer and converts it to a RESTAuthorizationException. This is a good practice as it:

  1. Maintains the REST API's exception hierarchy
  2. Properly encapsulates internal authorization exceptions
  3. Provides consistent error handling in the REST layer

This change directly addresses the null pointer issue mentioned in the PR objectives.

dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/CLRUAUserMetadataLinkRepository.java (3)

17-17: Import added for exception handling improvement.

The import of org.dspace.app.rest.exception.RESTAuthorizationException has been added to support the changes in exception handling.


46-47: Method signature updated to reflect exception handling changes.

The method signature has been modified to replace AuthorizeException with RESTAuthorizationException. This change aligns the method signature with the updated exception handling approach.


49-55: Improved exception handling to prevent null pointer exceptions.

The code now properly catches AuthorizeException thrown by the service layer and converts it to a RESTAuthorizationException. This change:

  1. Maintains consistent exception handling across the REST layer
  2. Aligns with the changes made in CLRUAUUserRegistrationLinkRepository
  3. Directly addresses the null pointer issue mentioned in the PR objectives

This implementation follows best practices for exception handling in a layered architecture by translating service-layer exceptions to appropriate REST-layer exceptions.

@milanmajchrak milanmajchrak changed the title ufal/clarinuserregistration nullpoint exception UFAL/Clarinuserregistration nullpoint exception Apr 22, 2025
@milanmajchrak milanmajchrak requested a review from vidiecan April 22, 2025 07:06
@milanmajchrak milanmajchrak merged commit 8eedba2 into dtq-dev Apr 22, 2025
11 checks passed
milanmajchrak added a commit that referenced this pull request Apr 22, 2025
* Enhanced file preview feature - Run file preview as authenticated user (#936), Property to allow composing file previews (#935), Do not create temp file during generating preview (#921)

* Use the handle url instead of the items url with the UUID (#938)

* Items file metadata not correctly updated (#940)

* Remove duplicate dependency element with identical content (warnings in build)

* Anonymous users should be able to use shortener

* Fixed internal server error, when context.commit() was called multiple times in search request

* Catch DSpaceBadRequestException rather than BadRequestException

* Fixed security issue for downloading file with non anonymous license

* Fixed Clarinuserregistration nullpoint exception (#941)
kosarko added a commit to ufal/clarin-dspace that referenced this pull request May 5, 2025
pulling changes from latest (lindat-2025.04.14600125143) dataquest release

This contains the following changes:

- UFAL/Run file preview as authenticated user (dataquest-dev#936)
- Property to allow composing file previews (dataquest-dev#935)
- File preview is not loaded properly for big zip file (dataquest-dev#921)
- UFAL/Clarinuserregistration nullpoint exception (dataquest-dev#941)
- UFAL/Use the handle url instead of the items url with the UUID (dataquest-dev#938)
- UFAL/Items file metadata not correctly updated (dataquest-dev#940)
- Synchronize ufal and dataquest main branches (dataquest-dev#939)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UFAL/ClarinUserRegistration endpoints throws nullpointer exception

4 participants