Skip to content

Conversation

@jenilpatel264
Copy link
Contributor

@jenilpatel264 jenilpatel264 commented Jun 16, 2025

This PR closes #12186

Added comprehensive validation and exception handling to ensure robust URI parsing and conversion to a URL in the create method. This improves reliability and user feedback by explicitly handling malformed or incomplete URI inputs.

Description

This PR enhances the create method to handle edge cases where the URI is malformed, incomplete, or improperly structured. Previously, certain invalid inputs could lead to unclear exceptions. This implementation improves error clarity and stability.

Changes

File: src/main/java/org/jabref/logic/util/URLUtil.java

What: Enhanced the create method with multiple validation checks and detailed exception handling.

Why: To ensure that only valid, absolute URIs with proper scheme and host are converted to URLs and to prevent ambiguous or uncaught runtime exceptions.

Detailed Explanation

Validation Checks Added:

  • Null or Empty Input:
    If the input url is null or an empty string (after trimming), a MalformedURLException is thrown with an appropriate message.

  • Absolute URI Check:
    Ensures the parsed URI is absolute before attempting conversion to a URL.

  • Scheme and Host Validation:
    Ensures that both the scheme (e.g., http, https) and host are present in the URI.

  • Improved Exception Handling:
    URISyntaxException: Catches invalid URI syntax and wraps it in a MalformedURLException with a detailed message.

  • IllegalArgumentException: Catches improper input such as illegal characters or encoding issues.

  • NullPointerException: Safeguards against unexpected null components in the URI.

  • Exception: Catches all other unforeseen issues during URI parsing or conversion.

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • [.] Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • [.] Screenshots added in PR description (if change is visible to the user)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@jenilpatel264 jenilpatel264 reopened this Jun 16, 2025
@Siedlerchr
Copy link
Member

please don't always open a new pr this creates noise for us, just push your change to your branch, the pr gets updated automatically

@koppor
Copy link
Member

koppor commented Jun 16, 2025

Tests are missing - see https://github.com/JabRef/jabref/pull/12800/files for example tests.

@calixtus
Copy link
Member

About the PR description: Do not put your code changes in there. Put it into the code. This is what the git diff in github is for.
Also mind the description for the checkboxes. Check what is applicable, mark as with / or . what is not applicable. Just checking everything is wrong. You did not change the documentation. You did not add screenshots.

@jenilpatel264
Copy link
Contributor Author

If I put . or / then the cases will failed, so what is the solution for this.

@jenilpatel264 jenilpatel264 requested a review from calixtus June 16, 2025 16:19
@calixtus calixtus changed the title changes for fix-for-issue-12186 Refine error message in URLUtil::create Jun 16, 2025
@calixtus calixtus added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers dev: code-quality Issues related to code or architecture decisions labels Jun 17, 2025
@calixtus calixtus enabled auto-merge June 17, 2025 17:38
subhramit
subhramit previously approved these changes Jun 17, 2025
@subhramit subhramit dismissed their stale review June 17, 2025 18:08

need to adapt tests after last commit

@subhramit subhramit removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jun 17, 2025
@subhramit
Copy link
Member

@jenilpatel264 please try to avoid using AI if you don't know what you are doing. It will not help you learn.

@subhramit subhramit disabled auto-merge June 17, 2025 18:38
@subhramit subhramit added the status: awaiting-second-review For non-trivial changes label Jun 17, 2025
@calixtus calixtus added this pull request to the merge queue Jun 17, 2025
@trag-bot
Copy link

trag-bot bot commented Jun 17, 2025

@trag-bot didn't find any issues in the code! ✅✨

Merged via the queue into JabRef:main with commit b8753ea Jun 17, 2025
1 check passed
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

I don't know if this really fixes the issue as when called www.example.org. there was another issue where the file field contained a URL without protocol...

Siedlerchr added a commit to MiguelCBar/jabref that referenced this pull request Jun 18, 2025
* upstream/main: (47 commits)
  Adapt some fetcher tests (JabRef#13370)
  change template issue number (JabRef#13367)
  Refine error message in URLUtil::create (JabRef#13337)
  fix deletion again (JabRef#13369)
  Only prevent failure in publishing from stopping the workflow (JabRef#13368)
  Refactor "enableFileAnnotationsTab" to "smartFileAnnotationsTab" and rewrote shouldShow in FileAnnotationTab as requested in JabRef#13279 (JabRef#13338)
  fix workflow (JabRef#13366)
  Fixamd64linux (JabRef#13365)
  Only delete for arm64 (JabRef#13364)
  New Crowdin updates (JabRef#13363)
  Bump org.junit.jupiter:junit-jupiter-api in /versions (JabRef#13362)
  Bump org.apache.logging.log4j:log4j-to-slf4j in /versions (JabRef#13359)
  Bump com.github.javaparser:javaparser-symbol-solver-core in /versions (JabRef#13361)
  Bump org.junit.platform:junit-platform-launcher in /versions (JabRef#13360)
  Bump com.fasterxml.jackson.datatype:jackson-datatype-jsr310 in /versions (JabRef#13358)
  Gradle build updates (JabRef#13319)
  Add "Disable GitHub actions" (JabRef#13356)
  Make jabref host executable on mac and on linux and fix import command line argument (JabRef#13355)
  Delete .github/workflows/merge-upstream.yml (JabRef#13357)
  chore(deps): update dependency org.apache.logging.log4j:log4j-to-slf4j to v2.25.0 (JabRef#13353)
  ...
Siedlerchr added a commit to ganesh-vk/jabref that referenced this pull request Jun 18, 2025
* upstream/main: (54 commits)
  Move publishing to maven central to a separate workflow (JabRef#13372)
  Add more guards to workflows not running on forked JabRef repos
  Copy real HTML from entry preview (JabRef#13339)
  Adapt some fetcher tests (JabRef#13370)
  change template issue number (JabRef#13367)
  Refine error message in URLUtil::create (JabRef#13337)
  fix deletion again (JabRef#13369)
  Only prevent failure in publishing from stopping the workflow (JabRef#13368)
  Refactor "enableFileAnnotationsTab" to "smartFileAnnotationsTab" and rewrote shouldShow in FileAnnotationTab as requested in JabRef#13279 (JabRef#13338)
  fix workflow (JabRef#13366)
  Fixamd64linux (JabRef#13365)
  Only delete for arm64 (JabRef#13364)
  New Crowdin updates (JabRef#13363)
  Bump org.junit.jupiter:junit-jupiter-api in /versions (JabRef#13362)
  Bump org.apache.logging.log4j:log4j-to-slf4j in /versions (JabRef#13359)
  Bump com.github.javaparser:javaparser-symbol-solver-core in /versions (JabRef#13361)
  Bump org.junit.platform:junit-platform-launcher in /versions (JabRef#13360)
  Bump com.fasterxml.jackson.datatype:jackson-datatype-jsr310 in /versions (JabRef#13358)
  Gradle build updates (JabRef#13319)
  Add "Disable GitHub actions" (JabRef#13356)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev: code-quality Issues related to code or architecture decisions status: awaiting-second-review For non-trivial changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

junie: IllegalArgumentException: URI is not absolute

5 participants