Skip to content

Auto file name truncation if path length exceeding limit while renaming on Windows#15488

Open
xIshanSandhux wants to merge 10 commits intoJabRef:mainfrom
xIshanSandhux:fix-14771-issue
Open

Auto file name truncation if path length exceeding limit while renaming on Windows#15488
xIshanSandhux wants to merge 10 commits intoJabRef:mainfrom
xIshanSandhux:fix-14771-issue

Conversation

@xIshanSandhux
Copy link
Copy Markdown
Contributor

@xIshanSandhux xIshanSandhux commented Apr 4, 2026

Related issues and pull requests

Closes #14771

PR Description

This PR is a bug fix which occurs on Windows. The bug occurs when the user tries to rename the file via the defined pattern option and if the title is very long Jabref does not truncate the title, and instead displays "JabRef cannot access the file because it is being used by another process." which is not the correct representation of the error that occurred.

As this bug occurred on windows and the issue had the label "platform: windows", the fix is only for windows and not for any other OS.

the function renameToName in LinkedFileHandler.java was throwing an IOException when calling Files.move().This was happening only when the newPath length was greater than the allowed limit (260 chars) on windows. The error was handled by performRenameWithConflictCheck() in LinkedFileViewModel.java which contains the base error that was being displayed to the user.

Fix in this PR

  • Added checks to see if the OS is windows and if the total path length including the new file name is greater than the MAX allowed limit.
  • If the above is true then the new filename gets truncated based on the available path limit.
  • Made the error handling better by checking if the current error is an instance of FileSystemException and if it is then display a better renaming failed error message.

I tested the fix with different file formats and its working as intended. Attached a few of them below.

Note: The allowed limit is 260 as the Max path length. However that also includes \0 therefore, the actual allowed limit for the path is 259. Which is why I used the 259 as the max const and not 260.

Also I have added a bit of debug statements as well. which was just for my own understanding, in order to find the bug. I can remove them if you guys want.

Also, there were some formatting changes that were happening automatically when saving the files (I am currently using intellij to edit the files). I will fix that.

Steps to test

  1. Open Jabref on Windows
  2. Create a entry with a long title.
    I used the following entry:
    @Article{Diringer2012, author = {Diringer, Yvan}, journal = {Lépidoptères - Revue des Lépidoptéristes de France}, pages = {56--63}, title = {Chronique d’élevage 4: l’élevage de l’{Azuré} de l’{Orobe}, {Polyommatus} ({Meleageria}) daphnis ({Denis} \& {Scuiffermuller}, 1775) notes complémentaires sur l’hybride cormion ({Nabokov}, 1941): {P.} ({L.}) coridon x {P.} ({M.}) daphnis ({Lepidoptera}: {Lycaenidae}}, volume = {21}, year = {2012}, number = {52}, file = {}, groups = {Polyommatus,Lysandra}, }
  3. Add a file to the entry
  4. Rename the file via the defined pattern option.

Snapshots of the Fix

File Renaming (truncation)

image image

Error Handling

image

screenshot showing a library with a single entry with me as author and as title the issue number (asked in the checklist):

image

Not sure if i need to add tests for this change.

Checklist

  • I own the copyright of the code submitted and I license it under the MIT license
  • I manually tested my changes in running JabRef (always required)
  • I added JUnit tests for changes (if applicable)
  • I added screenshots in the PR description (if change is visible to the user)
  • I added a screenshot in the PR description showing a library with a single entry with me as author and as title the issue number
  • I described the change in CHANGELOG.md in a way that can be understood by the average user (if change is visible to the user)
  • I checked the user documentation for up to dateness and submitted a pull request to our user documentation repository

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Apr 4, 2026
Comment thread .idea/codeStyles/codeStyleConfig.xml
Comment thread jabgui/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java Outdated
Comment thread jabgui/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java Outdated
Comment thread jabgui/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java Outdated
Comment thread jabgui/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java Outdated
Comment thread jabgui/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java Outdated
Comment thread jablib/src/main/java/org/jabref/logic/externalfiles/LinkedFileHandler.java Outdated
Comment thread jablib/src/main/java/org/jabref/logic/util/io/FileUtil.java Outdated
Comment thread jablib/src/main/java/org/jabref/logic/util/io/FileUtil.java Outdated
Comment thread jablib/src/main/java/org/jabref/logic/util/io/FileUtil.java Outdated
Comment thread jablib/src/main/java/org/jabref/logic/util/io/FileUtil.java Outdated
Comment thread jablib/src/main/java/org/jabref/logic/util/io/FileUtil.java Outdated
Comment thread jablib/src/main/java/org/jabref/logic/util/io/FileUtil.java Outdated
Comment thread jablib/src/main/java/org/jabref/logic/util/io/FileUtil.java Outdated
Comment thread jablib/src/main/java/org/jabref/logic/util/io/FileUtil.java Outdated
Comment thread .idea/codeStyles/codeStyleConfig.xml Outdated
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Apr 10, 2026
Copy link
Copy Markdown
Contributor Author

@xIshanSandhux xIshanSandhux left a comment

Choose a reason for hiding this comment

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

Currently looking into why the test check is failing and fixing it. However do lmk if I need to make any other changes

@github-actions github-actions bot added status: changes-required Pull requests that are not yet complete and removed status: no-bot-comments labels Apr 10, 2026
@xIshanSandhux xIshanSandhux requested a review from calixtus April 10, 2026 01:18
@calixtus calixtus self-assigned this Apr 15, 2026
@jabref-machine
Copy link
Copy Markdown
Collaborator

JUnit tests of jablib are failing. You can see which checks are failing by locating the box "Some checks were not successful" on the pull request page. To see the test output, locate "Source Code Tests / Unit tests (pull_request)" and click on it.

You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong error renaming file - open in another process

3 participants