Skip to content

Fix exclude consistency fields 13131 #13305

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lawmeyian
Copy link

@lawmeyian lawmeyian commented Jun 11, 2025

Closes #13131

This PR modifies the BibliographyConsistencyCheck to exclude specific fields from consistency checks. Fields such as COMMENT, CROSSREF, and AUTOMATIC_FIELDS, along with any SpecialField or UserSpecificCommentField, are now filtered out to avoid false positives during consistency validation. This improves the relevance of reported issues and aligns the behavior with user expectations.

Steps to test

  1. Open JabRef with a .bib file containing entries with fields such as comment, pdf, sortkey, groups, etc.
  2. Go to Quality > Check integrity or use the consistency check dialog.
  3. Observe that these excluded fields no longer trigger consistency warnings.
  4. Add a custom field not on the exclusion list and verify it is still flagged.
  5. Run unit tests in BibliographyConsistencyCheckTest — especially:
    •   filteredFieldsAreIgnored
      
    •   nonFilteredFieldDifferenceIsDetected
      

No UI changes were made, so testing is limited to data checks and developer view.

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.

Comment on lines +129 to +130
assertTrue(result.entryTypeToResultMap().isEmpty(),
"Differences only in filtered fields must be ignored");
Copy link

Choose a reason for hiding this comment

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

The use of assertTrue to check for an empty map is less informative than using assertEquals to directly compare the map to an empty map, which would provide clearer test failure messages.

// AUTHOR should be reported as a unique field
var typeResult = result.entryTypeToResultMap().get(StandardEntryType.Misc);
assertNotNull(typeResult);
assertTrue(typeResult.fields().contains(StandardField.AUTHOR));
Copy link

Choose a reason for hiding this comment

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

Using assertTrue to check if a collection contains an element is less informative than using assertEquals to compare the collection to an expected collection, which would provide clearer test failure messages.

@@ -69,7 +114,10 @@ public Result check(List<BibEntry> entries, BiConsumer<Integer, Integer> entries

List<BibEntry> differingEntries = entryTypeToEntriesMap
.get(entryType).stream()
.filter(entry -> !entry.getFields().equals(commonFields))
.filter(entry -> {
Set<Field> entryFiltered = filterFields(entry.getFields());
Copy link

Choose a reason for hiding this comment

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

The variable name 'entryFiltered' is not descriptive enough. It should convey the purpose or content of the variable more clearly.

@jabref-machine
Copy link
Collaborator

JUnit tests of jablib are failing. You can see which checks are failing by locating the box "Some checks were not successful" on the pull request page. To see the test output, locate "Tests / Unit tests (pull_request)" and click on it.

You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.

import java.util.function.BiConsumer;


Copy link
Member

Choose a reason for hiding this comment

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

Checkstyle

// – plus any SpecialField or UserSpecificCommentField (filtered at runtime)
// ----------------------------------------------------------------
private static final Set<Field> FILTERED_FIELDS = Stream
// start with JabRef’s built‐in AUTOMATIC_FIELDS set
Copy link
Member

Choose a reason for hiding this comment

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

Remove this comment, code is self-explanatory

Copy link
Member

Choose a reason for hiding this comment

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

The issue with AI comments is that if humans and AI both work in the code, it is not ensured if the comments match the implementation if the code is updated.

import org.jabref.model.entry.types.EntryType;

public class BibliographyConsistencyCheck {

// ----------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

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

Use proper Java doc, keep comment style

Comment on lines +59 to +61
.filter(f -> !FILTERED_FIELDS.contains(f))
.filter(f -> !(f instanceof SpecialField))
.filter(f -> !(f instanceof UserSpecificCommentField))
Copy link
Member

Choose a reason for hiding this comment

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

We avoid abbreviations

Suggested change
.filter(f -> !FILTERED_FIELDS.contains(f))
.filter(f -> !(f instanceof SpecialField))
.filter(f -> !(f instanceof UserSpecificCommentField))
.filter(field -> !FILTERED_FIELDS.contains(field))
.filter(field -> !(field instanceof SpecialField))
.filter(field -> !(field instanceof UserSpecificCommentField))

/**
* Drop any field we don’t want to check.
*/
private static Set<Field> filterFields(Collection<Field> fields) {
Copy link
Member

@subhramit subhramit Jun 11, 2025

Choose a reason for hiding this comment

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

Nitpick: Can you use a better method name, hinting at what we are filtering against? "filterFIelds" is a bit generic. Lets consider filterXFields or removeXFields - think what one word can "X" be, based on the logic?
If no such crisp word is possible, you can ignore this suggestion.

/**
* Drop any field we don’t want to check.
*/
private static Set<Field> filterFields(Collection<Field> fields) {
Copy link
Member

Choose a reason for hiding this comment

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

Also, we can be more specific here wrt the parameter

Suggested change
private static Set<Field> filterFields(Collection<Field> fields) {
private static Set<Field> filterFields(SequencedSet<Field> fields) {

"Differences only in filtered fields must be ignored");
}

@SuppressWarnings("checkstyle:RegexpMultiline")
Copy link
Member

Choose a reason for hiding this comment

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

Do not suppress checkstyle warnings without having a good reason to do so.

Copy link
Author

Choose a reason for hiding this comment

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

Hi subhramit,
thank you for your advice. I will fix it.

.withField(StandardField.COMMENT, "another note")
.withField(StandardField.PDF, "other.pdf");

var result = new BibliographyConsistencyCheck().check(List.of(a, b));
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use var. At JabRef, we prefer strict types.
Also, did the compiler not complain here? You sent one argument instead of two, so the unit test is failing. Did you run the test before filing the PR?

Comment on lines +141 to +144
var result = new BibliographyConsistencyCheck().check(List.of(withAuthor, withoutAuthor));

// AUTHOR should be reported as a unique field
var typeResult = result.entryTypeToResultMap().get(StandardEntryType.Misc);
Copy link
Member

Choose a reason for hiding this comment

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

Similar comments regarding var and number of arguments here as https://github.com/JabRef/jabref/pull/13305/files#r2140865139.

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.

Exclude certain fields from Consistency check
5 participants