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

Fix for IllegalArgumentException: URI is not absolute #12186 #12246

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

yash-agrawal03
Copy link

This PR closes: #12186

Added a check to ensure that the URI is absolute before converting it to a URL in the create method. This prevents the IllegalArgumentException: URI is not absolute error by throwing a MalformedURLException with a descriptive message if the URI is not absolute.

Description

This PR addresses a bug where the create method would throw an IllegalArgumentException if the URI was not absolute.

Changes

  1. File: src/main/java/org/jabref/logic/util/URLUtil.java
    • What: Added a check in the create method to ensure that the URI is absolute before converting it to a URL.
    • Why: To prevent the IllegalArgumentException: URI is not absolute error by throwing a MalformedURLException with a descriptive message if the URI is not absolute.

Detailed Explanation

  1. Added Check for Absolute URI:
    • Before converting the URI to a URL, the code now checks if the URI is absolute. If it is not, it throws a MalformedURLException.
public static URL create(String url) throws MalformedURLException {
    URI uri = createUri(url);
    if (!uri.isAbsolute()) {
        throw new MalformedURLException("URI is not absolute: " + url);
    }
    return uri.toURL();
}

This ensures that only valid absolute URIs are converted to URLs, preventing the error you encountered.

Mandatory checks

  • I own the copyright of the code submitted and I licence 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 (for UI changes)
  • 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.

… to a URL in the create method. This prevents the IllegalArgumentException: URI is not absolute error by throwing a MalformedURLException with a descriptive message if the URI is not absolute.
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Your code currently does not meet JabRef's code guidelines.
We use OpenRewrite to ensure "modern" Java coding practices.
The issues found can be automatically fixed.
Please execute the gradle task rewriteRun, check the results, commit, and push.

You can check the detailed error output by navigating to your pull request, selecting the tab "Checks", section "Tests" (on the left), subsection "OpenRewrite".

@yash-agrawal03
Copy link
Author

@koppor Could you please review the PR? I have resolved the bug that was present. Regarding the failing test case, it fails even when I run the script on the main branch's code. Could you check if this is an error on your side? Thank you

@subhramit
Copy link
Member

Regarding the failing test case, it fails even when I run the script on the main branch's code. Could you check if this is an error on your side? Thank you

Are you talking about the failing openrewrite test?

@yash-agrawal03
Copy link
Author

yash-agrawal03 commented Nov 30, 2024 via email

@subhramit
Copy link
Member

Yes, I’m talking about the openrewrite test.

Did you try fixing it? Following what is written in the bot message?
Also ref. https://devdocs.jabref.org/code-howtos/faq.html#failing-openrewrite-tests

@yash-agrawal03
Copy link
Author

yash-agrawal03 commented Nov 30, 2024 via email

@subhramit
Copy link
Member

I tried using the gradle rewriterun, but it just removed the library for
assert equals from the import and didn’t help me, pass the tests. Is there
any other workaround or docs to be followed?

Use the gradle sidebar and double click on the task as shown in the link.

@yash-agrawal03
Copy link
Author

yash-agrawal03 commented Nov 30, 2024 via email

Copy link
Member

@subhramit subhramit left a comment

Choose a reason for hiding this comment

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

Please also fix the submodules committed:
https://devdocs.jabref.org/code-howtos/faq.html#submodules

CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Subhramit Basu Bhowmick <[email protected]>
@koppor
Copy link
Member

koppor commented Nov 30, 2024

I tried using the gradle rewriterun,

Could you share the content of your JAVA_HOME setting?

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.

This is not a solution. JabRef should work with these "relative" URLs, too.

@yash-agrawal03
Copy link
Author

@koppor , This update does work with "realative" urls, can you please clarify a little or give some case, which I didn't cover? Thank You

@koppor
Copy link
Member

koppor commented Dec 2, 2024

@koppor , This update does work with "realative" urls, can you please clarify a little or give some case, which I didn't cover? Thank You

The example of #12186 (comment) should give no error, but work. Web page can be opened etc.

@koppor koppor marked this pull request as draft December 2, 2024 20:05
@koppor
Copy link
Member

koppor commented Dec 10, 2024

Closing this issue due to inactivity 💤

Please ping us if you intend to resume work on this one.

@koppor koppor closed this Dec 10, 2024
@yash-agrawal03
Copy link
Author

yash-agrawal03 commented Dec 10, 2024 via email

@koppor koppor reopened this Dec 10, 2024
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.

IllegalArgumentException: URI is not absolute
3 participants