From da9b099e1db3fa6c2750f4c2450ded28dd613e72 Mon Sep 17 00:00:00 2001 From: Niklas Date: Tue, 12 Aug 2025 17:17:26 +0200 Subject: [PATCH 1/6] Added function to handle empty values in the three-way migration There was an error when the year was empty in the comparison, if a value was empty. I've added a check to make sure that the values are not empty before the comparison. --- CHANGELOG.md | 1 + .../YearFieldValuePlausibilityComparator.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94c7613d9d0..b31b9fdb293 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,6 +99,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where the tab showing the fulltext search results would appear blank after switching library. [#13241](https://github.com/JabRef/jabref/issues/13241) - We fixed an issue where the groups were still displayed after closing all libraries. [#13382](https://github.com/JabRef/jabref/issues/13382) - Enhanced field selection logic in the Merge Entries dialog when fetching from DOI to prefer valid years and entry types. [#12549](https://github.com/JabRef/jabref/issues/12549) +- We fixed an issue where the year was empty on a bibliographic lookup.[#13673](https://github.com/JabRef/jabref/issues/13673) ### Removed diff --git a/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java b/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java index 5a9b48195ce..0f09e5d9099 100644 --- a/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java +++ b/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java @@ -29,6 +29,10 @@ public ComparisonResult compare(String leftValue, String rightValue) { Optional leftYear = extractYear(leftValue); Optional rightYear = extractYear(rightValue); + if (leftYear.isEmpty() || rightYear.isEmpty()) { + return checkEmptyValues(leftYear, rightYear); + } + boolean leftYearInRange = (leftYear.get() >= 1800) && (leftYear.get() <= Year.now().getValue() + 2); if (leftYearInRange) { @@ -59,4 +63,21 @@ private Optional extractYear(String value) { } return Optional.empty(); } + + /** + * Checks if one or both of the years are empty and returns the correct ComparisonResult + * + * @param leftValue year from the library (or candidate) + * @param rightValue year from the fetcher ((or existing record) + * @return ComparisonResult depending on which value is empty: RIGHT_BETTER, LEFT_BETTER, or UNDETERMINED + */ + private ComparisonResult checkEmptyValues(Optional leftValue, Optional rightValue) { + if (leftValue.isEmpty() && rightValue.isEmpty()) { + return ComparisonResult.UNDETERMINED; + } else if (leftValue.isEmpty()) { + return ComparisonResult.RIGHT_BETTER; + } else { + return ComparisonResult.LEFT_BETTER; + } + } } From f6e809e3e325398a7de4d8047cfbfe1751d9b2b1 Mon Sep 17 00:00:00 2001 From: Niklas Date: Thu, 14 Aug 2025 17:29:46 +0200 Subject: [PATCH 2/6] removed my previous method to simplify the desired result. --- .../YearFieldValuePlausibilityComparator.java | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java b/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java index 0f09e5d9099..79818f27a59 100644 --- a/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java +++ b/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java @@ -26,13 +26,15 @@ public ComparisonResult compare(String leftValue, String rightValue) { boolean leftValid = checker.checkValue(leftValue).isEmpty(); if (leftValid) { + boolean rightValid = checker.checkValue(rightValue).isEmpty(); + + if (rightValid) { + return ComparisonResult.LEFT_BETTER; + } + Optional leftYear = extractYear(leftValue); Optional rightYear = extractYear(rightValue); - if (leftYear.isEmpty() || rightYear.isEmpty()) { - return checkEmptyValues(leftYear, rightYear); - } - boolean leftYearInRange = (leftYear.get() >= 1800) && (leftYear.get() <= Year.now().getValue() + 2); if (leftYearInRange) { @@ -63,21 +65,4 @@ private Optional extractYear(String value) { } return Optional.empty(); } - - /** - * Checks if one or both of the years are empty and returns the correct ComparisonResult - * - * @param leftValue year from the library (or candidate) - * @param rightValue year from the fetcher ((or existing record) - * @return ComparisonResult depending on which value is empty: RIGHT_BETTER, LEFT_BETTER, or UNDETERMINED - */ - private ComparisonResult checkEmptyValues(Optional leftValue, Optional rightValue) { - if (leftValue.isEmpty() && rightValue.isEmpty()) { - return ComparisonResult.UNDETERMINED; - } else if (leftValue.isEmpty()) { - return ComparisonResult.RIGHT_BETTER; - } else { - return ComparisonResult.LEFT_BETTER; - } - } } From 742f8c924027d3b947907f0956bff68076783738 Mon Sep 17 00:00:00 2001 From: Niklas Date: Sat, 16 Aug 2025 19:47:39 +0200 Subject: [PATCH 3/6] readded the method, because it is needed for empty values. Added Tests --- .../YearFieldValuePlausibilityComparator.java | 27 ++++++++++++++----- ...rFieldValuePlausibilityComparatorTest.java | 23 ++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 jablib/src/test/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparatorTest.java diff --git a/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java b/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java index 79818f27a59..0f09e5d9099 100644 --- a/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java +++ b/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java @@ -26,15 +26,13 @@ public ComparisonResult compare(String leftValue, String rightValue) { boolean leftValid = checker.checkValue(leftValue).isEmpty(); if (leftValid) { - boolean rightValid = checker.checkValue(rightValue).isEmpty(); - - if (rightValid) { - return ComparisonResult.LEFT_BETTER; - } - Optional leftYear = extractYear(leftValue); Optional rightYear = extractYear(rightValue); + if (leftYear.isEmpty() || rightYear.isEmpty()) { + return checkEmptyValues(leftYear, rightYear); + } + boolean leftYearInRange = (leftYear.get() >= 1800) && (leftYear.get() <= Year.now().getValue() + 2); if (leftYearInRange) { @@ -65,4 +63,21 @@ private Optional extractYear(String value) { } return Optional.empty(); } + + /** + * Checks if one or both of the years are empty and returns the correct ComparisonResult + * + * @param leftValue year from the library (or candidate) + * @param rightValue year from the fetcher ((or existing record) + * @return ComparisonResult depending on which value is empty: RIGHT_BETTER, LEFT_BETTER, or UNDETERMINED + */ + private ComparisonResult checkEmptyValues(Optional leftValue, Optional rightValue) { + if (leftValue.isEmpty() && rightValue.isEmpty()) { + return ComparisonResult.UNDETERMINED; + } else if (leftValue.isEmpty()) { + return ComparisonResult.RIGHT_BETTER; + } else { + return ComparisonResult.LEFT_BETTER; + } + } } diff --git a/jablib/src/test/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparatorTest.java b/jablib/src/test/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparatorTest.java new file mode 100644 index 00000000000..1b957f5227f --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparatorTest.java @@ -0,0 +1,23 @@ +package org.jabref.logic.bibtex.comparator; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class YearFieldValuePlausibilityComparatorTest { + + private final YearFieldValuePlausibilityComparator comparator = new YearFieldValuePlausibilityComparator(); + @Test + void compareEmptyValuesTest() { + String emptyString = ""; + String validYearString = "1999"; + + ComparisonResult leftRight = ComparisonResult.LEFT_BETTER; + ComparisonResult rightRight = ComparisonResult.RIGHT_BETTER; + ComparisonResult undetermined = ComparisonResult.UNDETERMINED; + + assertEquals(rightRight, comparator.compare(emptyString, validYearString)); + assertEquals(leftRight, comparator.compare(validYearString, emptyString)); + assertEquals(undetermined, comparator.compare(emptyString, emptyString)); + } +} From db41653eb3061c32b7f6fdc8851c6842ea9ea7ef Mon Sep 17 00:00:00 2001 From: Niklas Date: Sun, 17 Aug 2025 03:47:49 +0200 Subject: [PATCH 4/6] Edited the CHANGELOG.md entry for [#13673] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72813819186..c1ce60cba8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,7 +101,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where the tab showing the fulltext search results would appear blank after switching library. [#13241](https://github.com/JabRef/jabref/issues/13241) - We fixed an issue where the groups were still displayed after closing all libraries. [#13382](https://github.com/JabRef/jabref/issues/13382) - Enhanced field selection logic in the Merge Entries dialog when fetching from DOI to prefer valid years and entry types. [#12549](https://github.com/JabRef/jabref/issues/12549) -- We fixed an issue where the year was empty on a bibliographic lookup.[#13673](https://github.com/JabRef/jabref/issues/13673) +- We fixed an issue where the year was empty on a bibliographic DOI data lookup.[#13673](https://github.com/JabRef/jabref/issues/13673) ### Removed From 29ece52f09573090d544142df0b389368621855c Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 18 Aug 2025 17:09:08 +0200 Subject: [PATCH 5/6] Edited the CHANGELOG.md entry for [#13673] Edited the comments for the checking of empty year values --- CHANGELOG.md | 2 +- .../comparator/YearFieldValuePlausibilityComparator.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1ce60cba8d..4ffd49037ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,7 +101,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where the tab showing the fulltext search results would appear blank after switching library. [#13241](https://github.com/JabRef/jabref/issues/13241) - We fixed an issue where the groups were still displayed after closing all libraries. [#13382](https://github.com/JabRef/jabref/issues/13382) - Enhanced field selection logic in the Merge Entries dialog when fetching from DOI to prefer valid years and entry types. [#12549](https://github.com/JabRef/jabref/issues/12549) -- We fixed an issue where the year was empty on a bibliographic DOI data lookup.[#13673](https://github.com/JabRef/jabref/issues/13673) +- We fixed an issue where the year was empty on a bibliographic DOI data lookup. [#13673](https://github.com/JabRef/jabref/issues/13673) ### Removed diff --git a/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java b/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java index 0f09e5d9099..7d2b07e46b1 100644 --- a/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java +++ b/jablib/src/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java @@ -65,10 +65,10 @@ private Optional extractYear(String value) { } /** - * Checks if one or both of the years are empty and returns the correct ComparisonResult + * Prevents the years from being empty, so the following logic has non empty values * * @param leftValue year from the library (or candidate) - * @param rightValue year from the fetcher ((or existing record) + * @param rightValue year from the fetcher (or existing record) * @return ComparisonResult depending on which value is empty: RIGHT_BETTER, LEFT_BETTER, or UNDETERMINED */ private ComparisonResult checkEmptyValues(Optional leftValue, Optional rightValue) { From 49622368d9c418f23b6f9eae172dac33c3ba20e9 Mon Sep 17 00:00:00 2001 From: LenHukiro <50771254+LenHukiro@users.noreply.github.com> Date: Thu, 21 Aug 2025 14:08:21 +0200 Subject: [PATCH 6/6] Update CHANGELOG.md Co-authored-by: Houssem Nasri --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e4e4e84514..4a3c66e2ed8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,7 +102,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where the tab showing the fulltext search results would appear blank after switching library. [#13241](https://github.com/JabRef/jabref/issues/13241) - We fixed an issue where the groups were still displayed after closing all libraries. [#13382](https://github.com/JabRef/jabref/issues/13382) - Enhanced field selection logic in the Merge Entries dialog when fetching from DOI to prefer valid years and entry types. [#12549](https://github.com/JabRef/jabref/issues/12549) -- We fixed an issue where the year was empty on a bibliographic DOI data lookup. [#13673](https://github.com/JabRef/jabref/issues/13673) +- We fixed an issue where the merge dialog throws an exception upon trying to load an entry with an invalid year field. [#13673](https://github.com/JabRef/jabref/issues/13673) ### Removed