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

Caught an error when accessing an invalid path. fixes #10548 #12038

Merged
merged 19 commits into from
Oct 23, 2024

Conversation

Boston54
Copy link
Contributor

Catches an error caused when the 'open library' button tries to open to a failed mounted directory on MacOS, making the button instead open to the user home directory.

This is achieved by adding a try-catch statement for an IllegalArgumentException in org.jabref.gui.importer.actions.OpenDatabaseAction.execute(), avoiding the potential of a race condition between when the path is checked to exist and when it is actually opened. If the path returned by getInitialDirectory() is inaccessible then the user home directory is used instead, as retrieved by Directories.getUserDirectory().

Closes #10548

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 applicable)
  • 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.

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.

While the PR was in progress, a new version of JabRef has been released.
You have to merge upstream/main and move your entry in CHANGELOG.md up to the section ## [Unreleased].

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 checked org.jabref.gui.util.FileDialogConfiguration.Builder#withInitialDirectory(java.nio.file.Path). It even checks for existance. - This is also reported at the issue somehow. The catch should be around when calling FileChooser.showOpenMultipleDialog.

Did you try it out? The issue talks about an ssh connection.

Test cases for org.jabref.gui.util.FileDialogConfiguration.Builder#withInitialDirectory(java.nio.file.Path) should be added.

Maybe a JUnit test can wrap https://github.com/google/jimfs and could help.

Maybe, just moving the try/catch around the right position and try out on macOS (!) is enough.

fileDialogConfiguration = builder
.withInitialDirectory(getInitialDirectory())
.build();
} catch (IllegalArgumentException e) { // something went wrong with the directory, fallback to user directory
Copy link
Member

Choose a reason for hiding this comment

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

Comment should go one line below

I think, the catch is at the wrong positon. See again the issue

java.lang.IllegalArgumentException: Folder parameter must be a valid folder
	at [email protected]/com.sun.glass.ui.CommonDialogs.convertFolder(CommonDialogs.java:239)
	at [email protected]/com.sun.glass.ui.CommonDialogs.showFileChooser(CommonDialogs.java:191)
	at [email protected]/com.sun.javafx.tk.quantum.QuantumToolkit.showFileChooser(QuantumToolkit.java:1719)
	at [email protected]/javafx.stage.FileChooser.showDialog(FileChooser.java:419)
	at [email protected]/javafx.stage.FileChooser.showOpenMultipleDialog(FileChooser.java:376)
	at [email protected]/org.jabref.gui.JabRefDialogService.showFileOpenDialogAndGetMultipleFiles(JabRefDialogService.java:398)
	```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep thats my bad, misread the stacktrace and didnt check it again.

What test cases are you looking for to test withInitialDirectory? There are already test cases present and it seems like they cover all cases? Or are you looking for a test case specific to the directory returned by Directories#getUserDirectory()

Copy link
Member

Choose a reason for hiding this comment

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

Mabye add a test case for a mounted path? how does it look like and why does it fail?

Copy link
Member

Choose a reason for hiding this comment

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

The catch needs to be around the open/show methhod

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure its possible to simulate a mounted directory in an automated test.

Correct me if I'm wrong, but since mounted directories are handled at the os-level and are treated identically to any other path at the application level, a path with a successful mount is no different to any other directory inside of a unit test, meaning that even if it was possible to simulate one in code, it wouldn't be any different to a regular path?

Did you instead mean that I should test for a failed mounted path?
I'm pretty sure I can use mockito for this to simulate an error being thrown by org.jabref.gui.DialogService#showFileOpenDialogAndGetMultipleFiles(org.jabref.gui.util.FileDialogConfiguration) when it gets called to replicate what happened in the original issue, but I don't see a way that I can write a useful test for org.jabref.gui.util.FileDialogConfiguration.Builder#withInitialDirectory(java.nio.file.Path) as requested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Yep thats my bad, misread the stacktrace and didnt check it again.

Did you move the block? Mayb,e we can let this through without any additonal test and blindly moving on. But the code should make the impression it could fix the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@koppor I was looking through jimfs and I've added it to the project, but to me it seems as though it isn't useful for simulating a true mounted directory (but you can 'simulate it' by basically just having a normal path that uses mount naming conventions and using your imagination).
I'm still using it though in the test I've written along with mockio to simulate what happened in the original issue (showFileOpenDialogAndGetMultipleFiles() throwing an IllegalArgumentException).

And yes, I've moved the block to be around the correct area. Since you are okay with not having a test that specifically simulates the mounted directory, I'll have a final check over it soon and then push it.

@Siedlerchr Siedlerchr added the status: changes required Pull requests that are not yet complete label Oct 20, 2024
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 Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

You can check review dog's comments at the tab "Files changed" of your pull request.

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 Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

You can check review dog's comments at the tab "Files changed" of your pull request.

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 Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

You can check review dog's comments at the tab "Files changed" of your pull request.

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".

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".

Siedlerchr
Siedlerchr previously approved these changes Oct 23, 2024
@Siedlerchr
Copy link
Member

Looks good to me now, please fix the openRewrite failure and then it's fine

@koppor
Copy link
Member

koppor commented Oct 23, 2024

I discarded the changes in the external-libraries.md, because we do not list test dependencies there. (Our guide is not good in this respect - sorry for that)

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".

@koppor
Copy link
Member

koppor commented Oct 23, 2024

@Boston54 managed to mock without some file system magic. Thus I removed jimfs dependency at b032b38 (#12038).

@koppor koppor added this pull request to the merge queue Oct 23, 2024
@koppor koppor removed the status: changes required Pull requests that are not yet complete label Oct 23, 2024
Merged via the queue into JabRef:main with commit 60e9ded Oct 23, 2024
23 checks passed
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.

No able to open a file once the folder value is invalid
3 participants