Skip to content

BibEntry class no longer implements Cloneable#13615

Merged
Siedlerchr merged 4 commits into
JabRef:mainfrom
chrisdenman:add-a-copy-constructor-for-BibEntry-13613
Jul 30, 2025
Merged

BibEntry class no longer implements Cloneable#13615
Siedlerchr merged 4 commits into
JabRef:mainfrom
chrisdenman:add-a-copy-constructor-for-BibEntry-13613

Conversation

@chrisdenman

@chrisdenman chrisdenman commented Jul 30, 2025

Copy link
Copy Markdown
Contributor

Closes #13613

  • Added 'copy constructor' public BibEntry(BibEntry other) { ... } with the logic borrowed from (now removed) clone() method.
  • Removed implements Cloneable from BibEntry.
  • Updated all referencing code.
  • This removes ugly typecasts on calling-sites, which is nice.

Steps to test

  • Run all the existing tests to ensure there's no regressions, there's no new functionality.
  • I've ensured there's no test regressions manually.

Mandatory checks

  • I own the copyright of the code submitted and I license 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 (if change is visible to the user)
  • 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.

  - Added 'copy constructor' public BibEntry(BibEntry other) { ... } with the logic borrowed from (now removed) 'clone()' method.
  - Removed 'implements Cloneable' from BibEntry.
  - Updated all referencing code.
@chrisdenman

Copy link
Copy Markdown
Contributor Author

From CONTRIBUTING.md § Add your change to CHANGELOG.md:

"If you did internal refactorings or improvements not visible to the user (e.g., UI, .bib file), then you don't need to put an entry there."

This change should not be visible to the user, unless it is broken.

@koppor

koppor commented Jul 30, 2025

Copy link
Copy Markdown
Member

From CONTRIBUTING.md § Add your change to CHANGELOG.md:

"If you did internal refactorings or improvements not visible to the user (e.g., UI, .bib file), then you don't need to put an entry there."

This change should not be visible to the user, unless it is broken.

Yes, therefore use[/] instead of [x] at the CHANGELOG item

koppor
koppor previously requested changes Jul 30, 2025

@koppor koppor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Besides two minor comments (one from me and one from trag bot): LGTM

Comment thread jablib/src/main/java/org/jabref/logic/citationstyle/JabRefItemDataProvider.java Outdated
@trag-bot

trag-bot Bot commented Jul 30, 2025

Copy link
Copy Markdown

@trag-bot didn't find any issues in the code! ✅✨

@InAnYan

InAnYan commented Jul 30, 2025

Copy link
Copy Markdown
Member

Thanks for quick fix!

@koppor, I think all issues are fixed, so you are free to approve

@Siedlerchr Siedlerchr enabled auto-merge July 30, 2025 18:40
@Siedlerchr Siedlerchr added this pull request to the merge queue Jul 30, 2025
Merged via the queue into JabRef:main with commit e73e83c Jul 30, 2025
1 check passed
UmutAkbayin pushed a commit to UmutAkbayin/jabref that referenced this pull request Aug 1, 2025
…abRef#13615

- Replaced clone() with BibEntry copy constructor in LinkedFileTransferHelper.
- Updated tests to reflect removal of Cloneable from BibEntry.
UmutAkbayin pushed a commit to UmutAkbayin/jabref that referenced this pull request Aug 1, 2025
…abRef#13615

- Replaced clone() with BibEntry copy constructor in LinkedFileTransferHelper.
- Updated tests to reflect removal of Cloneable from BibEntry.
Siedlerchr added a commit that referenced this pull request Aug 2, 2025
* upstream/main:
  Issue 13619 Make Citation relations text more clear. (#13620)
  Explain how to handle notifications (#13630)
  Fix scope of 'determine issue number' job (#13627)
  Add proper closing (#13626)
  Implement logic orchestration for Git Pull/Push operations (#13518)
  Make pattern for issue number more strict
  Fix "Cannot load file MultiMergeEntries.fxml" (#13624)
  Add Copy markdown to copy citation (#13387)
  Add ADR-0047 (#13621)
  Initial start of implementing a LSP for integrity checks (#13612)
  Refactor merge entries package structure (#13614)
  New Crowdin updates (#13616)
  BibEntry class no longer implements Cloneable (#13615)
  Fix dark mode in {} of Citation Relations tab of the entry editor (#13609)
  Update dependency org.kohsuke:github-api to v2.0-rc.4 (#13611)
  Fix setting of proxy without password (#13605)
github-merge-queue Bot pushed a commit that referenced this pull request Nov 25, 2025
* refactor(RightClickMenu): pass libraryTab to createCopySubMenu

Allows tracking the source BibDatabaseContext for later use in pasteEntry()

* feat(ClipBoardManager): add static BibDatabaseContext field with getter and setter

Enables tracking the source database context for use in pasteEntry()

* refactor(ClipBoardManager): change sourceDatabaseContext to instance variable

* feat(RightClickMenu): set sourceBibDatabaseContext from libraryTab

* feat: add LinkedFileTransferHelper#adjustLinkedFilesForTarget call to CopyTo#copyEntriesWithFeedback and LibraryTab#pasteEntry

* feat(CopyTo): support file preferences in copy operations

Add filePreferences parameter to CopyTo.java to enable
LinkedFile#findIn functionality

* feat(LinkedFileTransferHelper): add new helper class to support Entry transfer

* feat(LinkedFileTransferHelper): add helper to check reachability from primary directory

* test(LinkedFileTransferHelperTest): add test cases for LinkedFileTransferHelperTest#isReachableFromPrimaryDirectory method

* feat: adjust relative file paths after entry transfer between libraries

* feat(ImportHandler): clone entry in importEntryWithDuplicateCheck

Cloning the BibEntry in importEntryWithDuplicateCheck to ensure that
any file path adjustments during the copy/paste process do not affect
the original entry in the source database.

This avoids side effects when imported entries are modified (e.g. file links),
especially when the same BibEntry instance is shared between databases.

* chore: update LinkedFileTransferHelper#adjustLinkedFilesForTarget calls in LibraryTab and CopyTo to align with new method signature

* refactor: update LibraryTab#pasteEntry to copy with feedback

* feat(LinkedFileTransferHelper): enhance linked file adjustment and copying logic during entry transfer

* test(LinkedFileTransferHelperTest): add tests for all three scenarios

* docs(requirements): add file transfer requirements specification

* chore: remove unnecessary comments and adjust filed.ms to increment the heading leven only by one

* chore: replace Collection constructors with factories

* chore: remove DisplayNames for test classes

* chore: replace assertTrue with assertEquals

* refactor: change method signature to have boolean parameter last and change to collection constructors again

* refactor: replace IOException with Exception in the throws clause and remove unnecessary throws clauses

* refactor: remove unused import

* refactor: remove static modifier

* fix: add messages for pasting entries in the properties file

* chore: use BibEntry copy constructor in LinkedFileTransferHelper for #13615

- Replaced clone() with BibEntry copy constructor in LinkedFileTransferHelper.
- Updated tests to reflect removal of Cloneable from BibEntry.

* chore: align with style rules

* fix: improve error logging and update assertions in LinkedFileTransferHelper

* fix: reorganize imports and improve code formatting in LinkedFileTransferHelper

* fix: rename filed.md to files.md for clarity

* docs: add requirement traceability comments to LinkedFileTransferHelper

* fix: replace file existence check with atomic copy and exception handling

* chore(LinkesFileTransferHelperTest): replace setters with withers

* chore(LinkesFileTransferHelperTest): change back to setters

* fix: reject null in setSourceBibDatabaseContext to enforce fail-fast

* test: update LinkedFileTransferHelperTest to use Set for returned entries and consolidate assertions

- Replace multiple individual assertions with single assertEquals calls comparing expected and actual Sets of BibEntry
- Improves test clarity and maintainability by bundling assertions into one comprehensive check

* docs: clarify definition of "reachable" for linked files in file transfer context

* chore: add line for separation

* refactor: remove requireNonNull

* docs: update file transfer documentation for clarity and consistency

- pulled up the reachable definition before the list of requirements

* refactor: streamline linked file adjustment by using ifPresent for source context

* chore: move getSourceBibDatabaseContext method to improve code organization

* chore: fix indentation in module-info.java after rebase

* refactor: move clipboard context setting from RightClickMenu to EditAction#execute

- Removed clipBoardManager.setSourceBibDatabaseContext(...) from RightClickMenu
- Set the clipboard context dynamically in EditAction before copy and cut actions
- Improves separation of concerns and ensures correct clipboard context regardless of input method (menu, keyboard shortcut, toolbar)

* test: refactor test to align with project standards

- Uses proper camelCase instead of underscores
- Replaces nested classes with region/endregion comments
- Adds comprehensive test coverage for different file preference scenarios

* chore: change indents to 4 spaces to align with project standards

* chore: change indents to 4 spaces to align with project standards in LibraryTab and EditAction

* chore: use Optional without fully qualified class name

* chore: fix import order

* refactor: improve exception handling in file path adjustment

Remove overly broad Exception catch since no checked exceptions
are thrown in this block

* refactor: add nonnull annotation to parameters

* refactor: remove null check

BibEntry#getFiles will not return null, null check is unnecessary

* fix: use shared ClipBoardManager in EditAction

Previously, EditAction created a new ClipBoardManager, which caused copy, cut, and paste to not use the shared manager. Now EditAction uses the shared ClipBoardManager, fixing copy/paste and drag & drop behavior in the right-click menu and elsewhere.

* fix: remove unnecessry injector and adjust dropEntry to handle drag and drop

* chore: remove unused import

* refactor: update dropEntry methods to include source BibDatabaseContext for linked file adjustments

* refactor: remove databasecontext from FrameDndHandler again

* refactor: remove unused imports

* refactor: set databasecontext in FramDndHandler

* Add Nullable annotation

* Rename variable

* Fix typo in JavaDoc

* Better filename in case of tabs with same filename

* refactor: streamline clipboard management and linked file adjustments

* chore: remove unused import

* chore: remove block in switch expression

* Feature: Add option to deactivate the new feature by adjusting the file preferences

Users should be able to disable the automatic file adjustment/copying during transfers
via a preference setting (default: enabled).

* chore: adjust test cases to enable file copy feature

* chore: replace Collections#emptySet with Set#of to align with best practices

* chore: remove unused import

* refactor: extract copyEntiresWithFeedback method to own utility class

* chore: fix import order issues

* chore: fix import order issues in LinkedFileTransferHelper

* chore: fix localization issues

* chore: fix formatting issues

* chore: Update CHANGELOG: mention cut support

* Refine requirements

* WIP: Refine tests

* Add comment

* Fix condition

* Split condition to reduce load on the file system

* First version with FileTestConfiguration

* Update version

* Fix test

* Convert some tests

* Split up logging

* Adjust logging configuration

* Do nothing if file is not found

* Add another exit early

* Improve comment

* Refine data structure

* Introduce LinkMode for test files

* Minor logic change

* Add nullable annotation

* Move to "right" method

* Collect all imported files

* Add TODO

* Move entry selection to final import

* Move entries selection to tracker

* Add CHANGELOG.md entry

* Add forgotten method

* Remove class variables from method parameters

* Fix naming

* Remove more obsolete parameters

* Add sourceDatabaseContext - and file adjustment at import place

* More "natural" method paramter ordering

* Change algorithm

* Remove not-needed methods

* Add forgotten closing comment

* Fix logic

* other tests...

* Compilefix

* Use Optional instead of null

* Fix tests

* Fix test

* Begin to add BibTestConfiguration

* Finish BibTestConfiguration

* Fix tempDir - should be local to each test

* One more test

* Fix init

* New test configuraiton

* First round of "complete" tests

* tmpDir should be a local variable

* All tests are green

* Re-order test parameters

* Remove debugging "number"

* Adapt test

* Fix CHANGELOG.md

* Add TODO

* Re-link requirements

* Remove dead code (and adapt logging)

* Fix typo

* Add logger statement

* Refine code

* Semanticcal grouping in SrvStateManager

* Store BibContext and transfer mode in clipboard

* Refine comment

* Add ADR-054

* Remove unused variable

* Fix syntax

* Fix typo

* Split up into three properties

* Fix variable name

* Fix .fxml and add binding

* Refine wording

* Add skipping if not configured

* Remove obsolete =

* Fix recursion

* Fix linting issues

* Optimize imports...

* Fix imports

* Apply suggestions from code review

* Compilefix

* Fix CHANGELOG

---------

Co-authored-by: Umut Akbayin <umutakbayin@posteo.de>
Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
Co-authored-by: Christoph <siedlerkiller@gmail.com>
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.

Add a copy constructor for BibEntry

4 participants