Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix closing of JabRef in case of issues with index writer #10840

Merged
merged 8 commits into from
Feb 3, 2024

Conversation

koppor
Copy link
Member

@koppor koppor commented Jan 29, 2024

I started JabRef. Twice. Then, the same index is used for Lucene by the second instance. Does not work:

Could not initialize the IndexWriter
org.apache.lucene.store.LockObtainFailedException: Lock held by another program: /home/koppor/.local/share/jabref/lucene/99/06bf8206--y.bib/write.lock
...
Uncaught exception occurred in Thread[#60,JavaFX Application Thread,5,main]
java.lang.NullPointerException: Cannot invoke "org.apache.lucene.index.IndexWriter.getReader(boolean, boolean)" because "writer" is null

This PR adds a workaround by using null and Optionals.

This also adds a workaround for #10781 by checking for null. The workaround is the first code... OK, we could also check why the null appears here. Sounded like bigger work for that excpetional case.

This relates to #10841. The other PR is more on the loading task...

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • 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.

Uncaught exception occurred in Thread[#60,JavaFX Application Thread,5,main]
java.lang.NullPointerException: Cannot invoke "org.apache.lucene.index.IndexWriter.close()" because "this.indexWriter" is null
	at org.jabref@100.0.0/org.jabref.logic.pdf.search.PdfIndexer.close(PdfIndexer.java:299)
	at org.jabref@100.0.0/org.jabref.logic.pdf.search.PdfIndexerManager.shutdownIndexer(PdfIndexerManager.java:74)
	at org.jabref@100.0.0/org.jabref.gui.LibraryTab.onClosed(LibraryTab.java:792)
@calixtus
Copy link
Member

Not really happy. Why is indexDirectory null?
Well, workaround is better than nothing, but this is not a fix.
Please mark it with a comment "FixMe indexDirectory is null if a second instance of jabref tries to create an index" or sthg and open a new issue.

private IndexReader reader;

private PdfIndexer(BibDatabaseContext databaseContext, Directory indexDirectory, FilePreferences filePreferences) {
this.databaseContext = databaseContext;
this.indexDirectory = indexDirectory;
if (indexDirectory == null) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I checked the code. Especially org.jabref.model.database.BibDatabaseContext#getFulltextIndexPath. That never returns null.

Proposal: Ship that code and "check" if at some persons report that output. (Line 67). Then, we can track down the issue.

@koppor
Copy link
Member Author

koppor commented Jan 31, 2024

Added some comments. Should good to go now.

Copy link
Contributor

github-actions bot commented Jan 31, 2024

The build for this PR is no longer available. Please visit https://builds.jabref.org/main/ for the latest build.

@@ -45,16 +48,34 @@ public class PdfIndexer {
private static final Logger LOGGER = LoggerFactory.getLogger(PdfIndexer.class);

@VisibleForTesting
@Nullable // null might happen if lock is held by another JabRef instance
Copy link
Member

Choose a reason for hiding this comment

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

I am not a fan of this Nullable/non null annotations. Visible for testing is okay for me

@Siedlerchr Siedlerchr added this pull request to the merge queue Feb 3, 2024
@Siedlerchr Siedlerchr removed this pull request from the merge queue due to a manual request Feb 3, 2024
@Siedlerchr Siedlerchr added this pull request to the merge queue Feb 3, 2024
Merged via the queue into main with commit c261185 Feb 3, 2024
18 checks passed
@Siedlerchr Siedlerchr deleted the fix-indexwriter branch February 3, 2024 19:18
Siedlerchr added a commit that referenced this pull request Feb 6, 2024
* upstream/main:
  Bump org.apache.lucene:lucene-core from 9.9.1 to 9.9.2 (#10860)
  Bump org.junit.jupiter:junit-jupiter from 5.10.1 to 5.10.2 (#10863)
  Bump org.apache.lucene:lucene-highlighter from 9.9.1 to 9.9.2 (#10861)
  Bump org.tinylog:tinylog-api from 2.6.2 to 2.7.0 (#10862)
  Bump org.apache.lucene:lucene-queryparser from 9.9.1 to 9.9.2 (#10859)
  Bump gradle/wrapper-validation-action from 1 to 2 (#10858)
  Bump codecov/codecov-action from 3 to 4 (#10857)
  Bump peter-evans/create-pull-request from 5 to 6 (#10856)
  Update Gradle Wrapper from 8.5 to 8.6. (#10854)
  Enable auto merge of gradle wrapper update
  Jump to entry from cli (#10578)
  Fix closing of JabRef in case of issues with index writer (#10840)
  Update deployment-arm64.yml
  Fix secrents presence chcek
Siedlerchr added a commit to rdsingh13/jabref that referenced this pull request Feb 11, 2024
* upstream/main: (68 commits)
  BibTeX 'Title' to MS Office 'Publicationtitle' field (JabRef#10864)
  Introduce BibliographyConsistencyCheckResultTxtWriter (JabRef#10847)
  Upgrade gradle-build-action to actions/setup-gradle (JabRef#10866)
  Bump org.apache.lucene:lucene-core from 9.9.1 to 9.9.2 (JabRef#10860)
  Bump org.junit.jupiter:junit-jupiter from 5.10.1 to 5.10.2 (JabRef#10863)
  Bump org.apache.lucene:lucene-highlighter from 9.9.1 to 9.9.2 (JabRef#10861)
  Bump org.tinylog:tinylog-api from 2.6.2 to 2.7.0 (JabRef#10862)
  Bump org.apache.lucene:lucene-queryparser from 9.9.1 to 9.9.2 (JabRef#10859)
  Bump gradle/wrapper-validation-action from 1 to 2 (JabRef#10858)
  Bump codecov/codecov-action from 3 to 4 (JabRef#10857)
  Bump peter-evans/create-pull-request from 5 to 6 (JabRef#10856)
  Update Gradle Wrapper from 8.5 to 8.6. (JabRef#10854)
  Enable auto merge of gradle wrapper update
  Jump to entry from cli (JabRef#10578)
  Fix closing of JabRef in case of issues with index writer (JabRef#10840)
  Update deployment-arm64.yml
  use nio path
  fix submodules
  Fix secrents presence chcek
  Update deployment-arm64.yml
  ...
@koppor koppor mentioned this pull request Mar 17, 2024
6 tasks
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.

3 participants