Skip to content

Open folder as library (directory as library, phase 1) - #737

Open
koppor wants to merge 29 commits into
hayagriva-writerfrom
open-directory-library
Open

koppor wants to merge 29 commits into
hayagriva-writerfrom
open-directory-library

Conversation

@koppor

@koppor koppor commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

📚 Directory-as-library stack — bottom → top, each builds on the one below:

  1. Programmatic Hayagriva writer (directory-as-library, phase 0) #736 · Hayagriva YAML writer
  2. Open folder as library (directory as library, phase 1) #737 · Open folder as library ← this PR
  3. Live inbound sync for directory libraries (phase 2) #738 · Inbound file sync
  4. Write-back to Hayagriva sidecars (directory as library, phase 3) #739 · Write-back to sidecars
  5. Groups panel mirrors the directory structure (phase 4, #10930) #740 · Directory-structure groups
  6. Pattern-driven pair renames for directory libraries (phase 5a) #741 · Pattern-driven pair renames
  7. Mirror directory libraries into a .bib with git-sync merge-back #743 · .bib mirror + merge-back
  8. Convert .bib libraries into directory libraries #744 · Convert .bib → directory
  9. Make directory libraries reachable through the REST API #745 · REST API support
  10. Split DirectoryLibrarySynchronizer into collaborators #760 · Split the synchronizer

Related issues and pull requests

Phase 1 of the "directory as library" plan — see PLAN.md and phase 0 (#736, merged state assumed). Related to JabRef#10930 (directory-mirroring groups build on this later); no issue is closed by this PR.

PR Description

🤖 A new File > Open folder as library entry opens a directory as a JabRef library, filling the table from the Hayagriva sidecar files and PDFs found in the tree. A PDF beside a matching sidecar is linked to its entry; a PDF without one appears at once and gains its metadata and a citation key in the background, so opening never blocks. Directory libraries reopen on the next start.

jabref-contrib-policy:4.2:reviewed​:ok

Analogies

Like honey, the sidecar convention binds PDF and metadata together without any glue you can see. Like chocolate broken along its grooves, the directory tree splits naturally into entries — one square per sidecar, nested pieces included. And like the moon, most of this feature's mass (sync, write-back, groups) is still on the far side; this PR is the bright half you can already navigate by.

Steps to test

  1. Create a folder with a Hayagriva sidecar pair (smith2020.yml + smith2020.pdf), a bare PDF, and a subfolder with another pair.
  2. File > Open folder as library..., select the folder.
  3. The table fills instantly: sidecar entries (with journal/booktitle from Hayagriva parents and the PDF linked), plus a stub for the bare PDF that gains extracted metadata and a citation key moments later. The tab is titled after the folder:

Main table after opening a folder as library

  1. Closing the tab with modifications prompts "Save before closing" with the directory path; "Save as" writes a regular .bib.
  2. Quit JabRef and start it again: the folder tab is restored with the session:

Directory library restored after restart

Guarded by DirectoryLibraryScannerTest (pairing, nesting, gitignore/hidden skipping, non-Hayagriva YAML, broken-file warnings, no-write guarantee).

AI usage

Claude Code (model claude-fable-5).

AI CHECKLIST.md walkthrough

1. Code self-review

Nullability and control flow
  • No == null / != null checks in new code except Path.getFileName()/getParent() nullable returns of the JDK API.
  • No Objects.requireNonNull(...).
  • New classes annotated with @NullMarked.
  • Optional consumed with ifPresent / map / or — no isPresent() + get() blocks.
  • [/] StringUtil.isBlank(...) — no null-or-blank string checks needed.
Exceptions
  • No catch (Exception e); the scanner propagates IOException, the action surfaces failures via the background task's onFailure.
  • No throw new RuntimeException(...) / IllegalStateException(...).
  • Logged exception passed as last logger argument (visitFileFailed debug log).
Style and idioms
  • New BibEntry built with withers.
  • Modern Java: List.of(), records, Files.walkFileTree, text blocks in tests.
  • [/] Regexes — none added.
  • Background work uses org.jabref.logic.util.BackgroundTask.
  • No commented-out code, no trivial comments, no AI-disclosure comments.
  • Markdown Javadoc (///) with Markdown syntax.
User-facing text
  • All user-facing strings localized (Open folder as library..., error/warning messages).
  • Sentence case, no trailing !, no : labels.
  • Variance via placeholders ('%0').
Security
  • [/] No HTML output.
Tests
  • DirectoryLibraryScannerTest (11 tests) covers scan behavior incl. the no-write guarantee; GitIgnoreFileFilterTest moved along with the class and stays green.
  • Tests assert object contents with plain JUnit asserts, no @DisplayName, exceptions propagate, @TempDir used.

2. Verification commands

  • ./gradlew :jablib:check — 10721 tests, 2 failures in RemoteCommunicationTest only (local port occupied by a running JabRef instance on this machine; unrelated, pass on CI).
  • ./gradlew :jablib:checkstyleMain :jablib:checkstyleTest :jabgui:checkstyleMain.
  • ./gradlew :jablib:modernizer.
  • ./gradlew :rewriteRun left no diff (dry-run clean).
  • ./gradlew :jablib:javadoc.
  • ./gradlew traceRequirements (new req~directory-library.scan~1 covered by impl marker).
  • npx markdownlint-cli2 on the changed/added Markdown.
  • [/] IntelliJ-format docker image — not runnable here (no docker group); CI format job is the backstop.

3. Documentation

  • CHANGELOG.md entry added (TODO placeholder replaced with this PR's link after creation).
  • Issue search done; Dynamic group mirroring the file system. jabref#10930 related (linked, not closed).
  • Requirement added: docs/requirements/directory-library.md.
  • ADR added: docs/decisions/0072-directory-as-library-with-hayagriva-sidecars.md.

4. Pull request

  • PR body built from .github/PULL_REQUEST_TEMPLATE.md, every section filled.
  • All checklist items kept and marked.
  • All HTML comments removed.
  • PR created from a body file via gh api (same-owner cross-repo head needs head_repo).
  • CHANGELOG.md TODO replaced with the real PR link after creation, committed and pushed.

Checklist

  • I own the copyright of the code submitted and I license it under the MIT license
  • If AI tools were used, I disclosed them in the "AI usage" section and reviewed, understood, and take full ownership of all AI-generated code
  • I manually tested my changes in running JabRef (opened a demo folder via the new menu item on the X display; see screenshot)
  • 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 added one sentence (max 20 words) to CHANGELOG.md describing the change from the user's point of view (if the 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 — deferred until the feature stabilizes (write-back phase); tracked in PLAN.md phase 5

🤖 Generated with Claude Code

koppor and others added 2 commits July 13, 2026 23:13
A directory can now be opened as a library: the main table fills from
the Hayagriva .yml sidecars and PDFs found in the tree. Sidecar entries
link their same-basename PDF relative to the root; PDFs without a
sidecar become stub entries. The context gets the new
DatabaseLocation.DIRECTORY with an empty database path, which keeps
autosave/backup/change-monitor and path-dependent actions off by
default; "Save as" converts the tab into a regular .bib library.
GitIgnoreFileFilter moves to jablib for reuse by the scanner.

Edits are not yet written back to the files; live synchronization and
write-back follow in later steps (see PLAN.md on directory-as-library).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
koppor and others added 6 commits July 14, 2026 02:03
PDFs without a sidecar now go through PdfMergeMetadataImporter (the
standard PDF import pipeline: embedded BibTeX, XMP, content heuristics,
plus GROBID/identifier lookups as configured) instead of becoming
filename-only stubs; the stub remains the fallback when nothing usable
can be extracted. The new PdfEntryFactory carries this behavior so the
file watcher can reuse it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Entries created for PDFs without a sidecar get a citation key from the
configured pattern after insertion, so the uniqueness check sees the
whole library. Sidecar entries keep their Hayagriva key untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Opening a folder no longer blocks on PDF parsing or identifier lookups:
the scan inserts quick stub entries for sidecar-less PDFs and the new
PdfEnrichmentTask extracts their metadata in the background afterwards,
enriching each stub in place (progress shown in the task overlay,
cancellable). Enrichment mutations carry EntriesEventSource.SHARED
because they are system-initiated, not user edits; the citation key is
generated per entry once its metadata arrived.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
When the PDF itself yields no DOI, the DOI is looked up via CrossRef
(the same reverse search as the magnifier button next to the DOI field)
and the metadata behind it merges into the entry with set-if-empty
semantics (BibEntry#mergeWith): PDF-extracted values are never
overwritten, the DOI metadata only fills the gaps. PDFs that already
carry a DOI keep being enriched by PdfMergeMetadataImporter itself.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Directory libraries were skipped by the session store because they have
no database path; their root directory now stands in, and paths that
turn out to be directories are routed from openFiles to the
directory-library opener on the next start.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The directory-library spec gains a Markdown sidecar form: X.md next to
X.pdf, whose YAML frontmatter is a regular Hayagriva document and whose
body carries the long-form notes (# Notes for the comment field, one
## comment-<name> section per per-user comment). Long-form Markdown
notes read terribly as YAML block scalars; as a Markdown body the
folder doubles as a plain notes collection (Obsidian, any editor). The
scanner imports such files next to plain .yml/.yaml Hayagriva files.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q5Y5GTihE9rZxKrvPqnHV4
koppor and others added 9 commits September 3, 2026 03:18
Resync layer 2 of the stack. Conflicts: import-block collision in
UnlinkedFilesCrawler (kept all three imports), and a semantic conflict
from upstream's UndoManager -> GuiUndoManager refactor — retyped
OpenDirectoryLibraryAction's undo manager to GuiUndoManager to match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcHNMt9fPWnpYaHheFvry
Upstream took 0066 in the meantime; the MADR check rejects the duplicate id.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vr3E1Gg5DRU4LQDDVnhPys
A failed "Save as" no longer strips the directory library of its root; the background PDF enrichment is cancelled with the tab, logs failures, and no longer marks the library as modified; opening an already open folder raises its tab; extensions match case-insensitively and gitignored PDFs are not paired. Optional/null idioms follow the checklist.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vr3E1Gg5DRU4LQDDVnhPys
Fixes the CI format check.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcHNMt9fPWnpYaHheFvry
Upstream dropped the undo manager from LibraryTab.createLibraryTab and
added a GitHandlerRegistry; OpenDirectoryLibraryAction and its callers
follow suit.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcHNMt9fPWnpYaHheFvry
Upstream added a 0071 ADR after this stack claimed the number, so the
MADR duplicate-ID check failed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
koppor and others added 3 commits September 8, 2026 00:21
# Conflicts:
#	jabgui/src/main/java/org/jabref/gui/LibraryTab.java
Main took 0072.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CajtxjcCEjS87f4hoTBTJD
koppor and others added 3 commits September 13, 2026 21:48
A folder whose `.gitignore` ignores everything — a `*` catch-all next to a
`.gitkeep`, the common shape of a scratch PDF folder — opened as an empty
library, because the scanner ran every PDF and sidecar through the gitignore
filter. The filter now applies only to non-content files; hidden files and
ignored subtrees are still skipped.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcHNMt9fPWnpYaHheFvry
A directory library resolves every linked file against its single root, so the
library- and user-specific file directory overrides in the library properties
do not apply. Both rows are now disabled when the library is a directory library.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcHNMt9fPWnpYaHheFvry
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (9)

Grey Divider


Action required

1. Opening a folder immediately prompts to save 🐞 Bug
Description
setupMainPanel() marks every nonempty library without a database path as changed, including newly
scanned directory libraries. Because requestClose() now prompts for changed directory libraries,
closing one immediately after opening it asks the user to save despite no edits.
Code

jabgui/src/main/java/org/jabref/gui/LibraryTab.java[R866-868]

+        // DIRECTORY prompts as well: until file write-back exists, edits are in-memory only
+        if (bibDatabaseContext.getLocation() == DatabaseLocation.LOCAL
+                || bibDatabaseContext.getLocation() == DatabaseLocation.DIRECTORY) {
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A populated directory library is marked changed during initial tab setup, so closing it prompts to save without any user edits.

## Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/LibraryTab.java[768-783]
- jabgui/src/main/java/org/jabref/gui/LibraryTab.java[865-870]

## Recommended Fix
Exclude directory libraries from the unsaved-import `markChanged()` branch while retaining change tracking and close prompts for actual subsequent user edits. Add a test that opens and closes a populated directory library without editing it.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. PDF extraction overwrites a user's edits 🐞 Bug
Description
applyExtractedMetadata() sets every extracted non-file field on the live stub without checking
whether its value has changed since the scan. If a user edits the placeholder title while background
extraction or lookup is running, the later result replaces that edit.
Code

jablib/src/main/java/org/jabref/logic/directorylibrary/PdfEntryFactory.java[R103-106]

+        extracted.getFields().stream()
+                 .filter(field -> StandardField.FILE != field)
+                 .forEach(field -> extracted.getField(field).ifPresent(
+                         value -> stub.setField(field, value, EntriesEventSource.SHARED)));
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Background PDF metadata replaces fields that a user edited after the stub appeared.

## Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/directorylibrary/PdfEntryFactory.java[88-107]
- jablib/src/main/java/org/jabref/logic/directorylibrary/PdfEnrichmentTask.java[43-57]

## Recommended Fix
Capture the stub's initial values or edit state and apply each extracted field only if the live value still matches the initial value; similarly protect changes to entry type. Test editing the title before delivering an extracted result.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. One badly encoded or unreadable file aborts opening the folder 🐞 Bug
Description
DirectoryLibraryScanner.scan() does not catch IOException from looksLikeHayagriva or
MarkdownSidecar.looksLikeSidecar/read while processing individual sidecar candidates. A
non-UTF-8 or unreadable YAML or Markdown file can therefore abort the scan after traversal,
preventing the other PDFs and sidecars from being opened.
Code

jablib/src/main/java/org/jabref/logic/directorylibrary/DirectoryLibraryScanner.java[R94-100]

+            boolean isMarkdown = MarkdownSidecar.hasMarkdownExtension(sidecarFile);
+            if (isMarkdown ? !markdownSidecar.looksLikeSidecar(sidecarFile) : !looksLikeHayagriva(sidecarFile)) {
+                continue;
+            }
+            ParserResult parserResult = isMarkdown
+                                        ? markdownSidecar.read(sidecarFile)
+                                        : importer.importDatabase(sidecarFile);
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A sidecar candidate that cannot be read or decoded as UTF-8 stops the directory scan and prevents the folder from opening. Handle failures for individual files without suppressing failures of directory traversal itself.

## Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/directorylibrary/DirectoryLibraryScanner.java[90-112]
- jablib/src/main/java/org/jabref/logic/directorylibrary/DirectoryLibraryScanner.java[182-190]

## Recommended Fix
Catch `IOException` around each sidecar candidate’s recognition and import, then continue scanning the remaining files. Log a non-UTF-8 file that is not recognized as a sidecar at debug level; for a file identified as Hayagriva that cannot be read, add the existing “Could not parse the Hayagriva file '%0'.” warning. Record a warning identifying any other affected candidate that cannot be read. Leave directory-traversal failures available to the caller, and add a test with a Latin-1 `README.md` in the tree.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

4. Valid sidecars can disappear from scans 🐞 Bug
Description
looksLikeHayagriva() and Markdown frontmatter recognition rely on the importer's bounded,
whole-line type: lookahead rather than the full YAML parse. A valid sidecar with an inline comment
after type: article, or with that line beyond 3,000 characters, fails recognition and is silently
skipped before import.
Code

jablib/src/main/java/org/jabref/logic/directorylibrary/DirectoryLibraryScanner.java[R94-96]

+            boolean isMarkdown = MarkdownSidecar.hasMarkdownExtension(sidecarFile);
+            if (isMarkdown ? !markdownSidecar.looksLikeSidecar(sidecarFile) : !looksLikeHayagriva(sidecarFile)) {
+                continue;
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The scanner discards valid YAML and Markdown sidecars when their `type:` syntax or position defeats the lightweight recognizer.

## Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/directorylibrary/DirectoryLibraryScanner.java[90-106]
- jablib/src/main/java/org/jabref/logic/directorylibrary/MarkdownSidecar.java[58-67]

## Recommended Fix
Use recognition that accepts the full valid YAML syntax for both sidecar forms, while keeping arbitrary non-Hayagriva files excluded and malformed recognized sidecars reported as warnings. Cover inline YAML comments and long leading content in tests.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View medium (4)
5. Other note sections enter entry comments 🐞 Bug
Description
applyBody() recognizes ## boundaries but skips only the first # heading, regardless of its
name, and does not treat subsequent top-level headings as boundaries. Content under a heading such
as # Introduction becomes the entry comment, while a later # Notes can be appended to a
preceding user's comment section.
Code

jablib/src/main/java/org/jabref/logic/directorylibrary/MarkdownSidecar.java[R122-126]

+            if (line.startsWith(SECTION_HEADING_PREFIX)) {
+                applySection(entry, currentSection, currentText.toString());
+                currentSection = line.substring(SECTION_HEADING_PREFIX.length()).strip();
+                currentText.setLength(0);
+            } else if (!titleSkipped && currentSection.isEmpty() && currentText.toString().isBlank() && line.startsWith("# ")) {
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The Markdown reader attributes file-only sections and later top-level sections to entry comment fields.

## Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/directorylibrary/MarkdownSidecar.java[115-145]

## Recommended Fix
Track top-level headings as section boundaries, import the `# Notes` content into the shared comment and `## comment-*` content into the matching user comment, and ignore content under unrelated headings. Preserve the supported heading-free comment body and test headings before and after Notes.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. Subfolder .gitignore files are not respected 🐞 Bug
Description
collectFiles reuses one GitIgnoreFileFilter(root) throughout the walk instead of calling
forSubdirectory to load nested ignore rules. When a subfolder has a .gitignore that excludes a
child folder, the scan still reaches that folder’s PDFs, sidecars, and other non-content files.
Code

jablib/src/main/java/org/jabref/logic/directorylibrary/DirectoryLibraryScanner.java[R131-136]

+        GitIgnoreFileFilter gitIgnoreFilter = new GitIgnoreFileFilter(root);
+        Files.walkFileTree(root, new SimpleFileVisitor<>() {
+            @Override
+            public FileVisitResult preVisitDirectory(Path directory, BasicFileAttributes attributes) throws IOException {
+                if (!directory.equals(root) && (isHidden(directory) || !gitIgnoreFilter.accept(directory))) {
+                    return FileVisitResult.SKIP_SUBTREE;
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The directory library scan uses only the root’s gitignore filter, so `.gitignore` files in subfolders do not exclude their files or subtrees.

## Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/directorylibrary/DirectoryLibraryScanner.java[130-173]
- jablib/src/main/java/org/jabref/logic/util/io/GitIgnoreFileFilter.java[72-74]

## Recommended Fix
Maintain a `Deque<GitIgnoreFileFilter>` in the visitor. In `preVisitDirectory`, use the current parent filter to decide whether to enter a directory, then push `forSubdirectory(directory)` for entered subdirectories; push the existing root filter for the root itself. Use the active filter in `visitFile` and pop it in `postVisitDirectory`. Add a test with a nested `.gitignore` that excludes a folder containing a PDF.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


7. A catch-all .gitignore hides all PDFs in subfolders 🐞 Bug
Description
visitFile lets library content (PDFs and sidecars) bypass .gitignore, but preVisitDirectory
still applies gitIgnoreFilter.accept(directory) to every subdirectory. A * rule in the root's
(or an ancestor's) .gitignore, the scratch-folder setup this PR names, matches every subfolder, so
their whole subtrees are skipped. Only PDFs at the top level appear, which contradicts the
requirement that the library's own sidecars and PDFs are never hidden by .gitignore.
Code

jablib/src/main/java/org/jabref/logic/directorylibrary/DirectoryLibraryScanner.java[R135-137]

+                if (!directory.equals(root) && (isHidden(directory) || !gitIgnoreFilter.accept(directory))) {
+                    return FileVisitResult.SKIP_SUBTREE;
+                }
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A catch-all `*` .gitignore prunes every subdirectory, so nested PDFs and sidecars disappear despite the documented exemption.

## Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/directorylibrary/DirectoryLibraryScanner.java[134-139]
- docs/requirements/directory-library.md[18-21]

## Recommended Fix
Option 1: stop pruning subtrees that are matched only by wildcard file patterns, and prune only directories explicitly matched (e.g. `drafts/`). Option 2: document in the requirement that ignored subfolders are skipped even under a catch-all rule. Add a test with `*` at the root and a subfolder pair.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


8. Opening a drive root as a library crashes 🐞 Bug
Description
updateTabTitle() calls root.getFileName().toString() on a directory library root, even though
getFileName() returns null for filesystem roots such as E:\ or /. Selecting such a root
reaches this branch when the directory tab is created, so title construction throws a
NullPointerException before the tab title and tooltip are set.
Code

jabgui/src/main/java/org/jabref/gui/LibraryTab.java[R648-651]

+                bibDatabaseContext.getDirectoryLibraryRoot().ifPresent(root -> {
+                    tabTitle.append(root.getFileName().toString());
+                    toolTipText.append(root.toAbsolutePath());
+                });
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A directory tab cannot render its title when the selected directory is a filesystem or drive root because `getFileName()` returns null.

## Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/LibraryTab.java[644-651]

## Recommended Fix
Use the root path's string representation when `getFileName()` returns null, for example `Optional.ofNullable(root.getFileName()).map(Path::toString).orElse(root.toString())`, and test title rendering for a filesystem-root directory.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



View low (1)
Informational
9. Opening the same folder twice quickly creates duplicate tabs 🐞 Bug
Description
openDirectory() checks only existing tabs for a library root, then starts an asynchronous scan
without marking that root as in progress; scanAndShow adds a tab only on success. If another
request arrives before the scan finishes—including through a separate restore action instance—both
requests pass the check and create tabs for the same directory, each running PDF enrichment and
network lookups.
Code

jabgui/src/main/java/org/jabref/gui/importer/actions/OpenDirectoryLibraryAction.java[R86-92]

+        tabContainer.getLibraryTabs().stream()
+                    .filter(tab -> tab.getBibDatabaseContext().getDirectoryLibraryRoot()
+                                      .map(openRoot -> openRoot.toAbsolutePath().normalize())
+                                      .filter(root::equals)
+                                      .isPresent())
+                    .findFirst()
+                    .ifPresentOrElse(tabContainer::showLibraryTab, () -> scanAndShow(root));
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Concurrent open requests for one directory can produce duplicate library tabs while scans are unfinished.

## Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/importer/actions/OpenDirectoryLibraryAction.java[84-106]
- jabgui/src/main/java/org/jabref/gui/importer/actions/OpenDirectoryLibraryAction.java[108-123]

## Recommended Fix
Track normalized roots being scanned in state shared across action instances, such as a static or tab-container-scoped set. Skip requests for roots already in that set, clear each root on both success and failure, and ensure only one completion creates a tab per root. Alternatively, add a loading tab immediately, as `OpenDatabaseAction` does.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

This branch has not been deployed

No deployments
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.

1 participant