Skip to content

Conversation

@2705DeeptiN
Copy link

Closes #3590

This PR updates the Recent Files feature so that stored file paths are converted from absolute paths to project-relative paths. This fixes issues where Recent Files breaks when the project folder is moved or shared across machines. This improves portability and consistency for users working in multiple environments.

Steps to test

  1. Open JabRef.
  2. Open any .bib file located inside a folder (e.g., a project directory).
  3. Close JabRef and reopen it.
  4. Move the entire folder to another location.
  5. Open JabRef again.
  6. Check the Recent files list — it should correctly resolve and open the .bib file using the relative path.

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • I manually tested my changes in running JabRef
  • I added JUnit tests for changes (if applicable)
  • I added screenshots in the PR description (if change is visible to the user)
  • I described the change in CHANGELOG.md in a way understandable for the average user (if visible)
  • I checked the user documentation and updated/created issues if needed

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Nov 30, 2025
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Nov 30, 2025
@calixtus
Copy link
Member

Thank you for your initial code. Please add missing tests.

@calixtus calixtus added the status: changes-required Pull requests that are not yet complete label Nov 30, 2025
@github-actions github-actions bot added status: changes-required Pull requests that are not yet complete and removed status: changes-required Pull requests that are not yet complete labels Nov 30, 2025
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 2, 2025
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.

Code comments need to be added on the absolute/relative thing. There is no code comment about the where relative and absolute paths are stored etc.

I miss handling of #3590 (comment) - and your PR comment doesn't say anything about this.

Thus this PR reads like a quick fix than a well-through-through thing? I also miss screenshots.

Comment on lines +58 to +60
if (absolutePath == null) {
return null;
}
Copy link
Member

Choose a reason for hiding this comment

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

When can this happen? Maybe annotate paramter as @NonNull?

try {
return workingDir.relativize(absolutePath);
} catch (Exception e) {
return absolutePath; // fallback
Copy link
Member

Choose a reason for hiding this comment

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

Do a LOGGER.error, because this should be fixed maybe?

Comment on lines +69 to +74
private Path toAbsolute(Path storedPath) {
if (storedPath == null) {
return null;
}
Path workingDir = Path.of("").toAbsolutePath();
if (!storedPath.isAbsolute()) {
Copy link
Member

Choose a reason for hiding this comment

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

See above.

Comment on lines 43 to 46
/**
* Adds the file to the top of the list. If it already is in the list, it is merely moved to the top.
* Adds the file to the top of the list. If it already is in the list, it is
* merely moved to the top.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why the reformatting here?

public void newFile(Path file) {
removeItem(file);
this.addFirst(file);
this.addFirst(toRelative(file.toAbsolutePath()));
Copy link
Member

Choose a reason for hiding this comment

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

Wait, what?

Comment on lines +64 to +79
private Path toRelative(Path absolutePath) {
Path workingDir = Path.of("").toAbsolutePath();
try {
return workingDir.relativize(absolutePath);
} catch (Exception e) {
return absolutePath; // fallback
}
}

private Path toAbsolute(Path storedPath) {
Path workingDir = Path.of("").toAbsolutePath();
if (!storedPath.isAbsolute()) {
return workingDir.resolve(storedPath).normalize();
}
return storedPath;
}
Copy link
Member

Choose a reason for hiding this comment

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

This is duplicated code.

Strong indication that used at too many places.

Maybe you can use org.jabref.logic.util.io.FileUtil#relativize(java.nio.file.Path, java.util.List<java.nio.file.Path>) ?

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 2, 2025
return new FileHistory(new ArrayList<>(list));
}

private Path toRelative(Path absolutePath) {
Copy link
Member

Choose a reason for hiding this comment

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

This definetitely needs a test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: changes-required Pull requests that are not yet complete

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow relative paths in Recent Libraries

4 participants