Fix: Prevent creating duplicate and empty entry type#15107
Conversation
|
Hey @pluto-han! 👋 Thank you for contributing to JabRef! We have automated checks in place, based on which you will soon get feedback if any of them are failing. We also use Qodo for review assistance. It will update your pull request description with a review help and offer suggestions to improve the pull request. After all automated checks pass, a maintainer will also review your contribution. Once that happens, you can go through their comments in the "Files changed" tab and act on them, or reply to the conversation if you have further inputs. You can read about the whole pull request process in our contribution guide. Please ensure that your pull request is in line with our AI Usage Policy and make necessary disclosures. |
✅ All tests passed ✅🏷️ Commit: 60d5e9a Learn more about TestLens at testlens.app. |
|
Do not mark a PR as ready-for-review while the CI is running. CI checks need to be completed and passed. |
Review Summary by QodoPrevent duplicate and empty entry type creation with validation
WalkthroughsDescription• Prevent creating duplicate entry types by checking existing types • Prevent creating empty or space-containing entry types with validation • Unify entry type creation logic for '+' button and Enter key • Select and scroll to existing entry type when duplicate name entered Diagramflowchart LR
A["User input entry type name"] --> B{"Validation check"}
B -->|Invalid| C["Show warning message"]
B -->|Valid| D{"Check for duplicates"}
D -->|Duplicate found| E["Select existing entry type"]
D -->|No duplicate| F["Create new entry type"]
E --> G["Scroll to entry type"]
F --> G
File Changes1. jabgui/src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTab.java
|
Code Review by Qodo
1. Changelog grammar in bullets
|
I will work on it. |
|
Note: Upgrading from 5.15 to this PR is without hassle. How I tested:
Everything correct 👍 We are backwards compatible too, as users on old versions can import the new non-standard entry type configs as "custom entry type", which then again is perfectly fine to upgrade from. |
* Fix saving duplicate and empty entry type * Fix saving duplicate and empty entry type * update CHANGELOG.md * Fix saving duplicate and empty entry type

Related issues and pull requests
Closes #15074
Closes #15103
PR Description
This PR fixes the issue where entry types with duplicate or empty names can be created. These changes improve data integrity and provide a more reliable and predictable user experience when managing entry types. To address #15074, I add a duplicate check to find duplicate entry types. If check passes, a new entry type will be created, otherwise it will select existing entry type. To address #15103, I refactored the logic so that both the '+' button and the Enter key trigger the same method and then run validity check.
Required Verification Screenshot:

Test Video:
https://github.com/user-attachments/assets/10f1b0d3-5765-46b1-8f21-76a1be1b98a4
Steps to test
Follow https://docs.jabref.org/setup/customentrytypes, open File -> Preferences -> Entry types
Type some spaces or a string with spaces (e.g. "te st") or leave entry type empty
Click '+' button or press enter key
Expected result: No entry types are created, JabRef warns users 'Entry type cannot be empty and must not contain spaces.'
Type 'book'
Expected result: Select and scroll to existing entry type 'Book'
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)