Skip to content

Added Backingstore, setAll and getAll methods, modified Helper Method…#14941

Closed
aaryyya wants to merge 3 commits intoJabRef:mainfrom
aaryyya:fix_NameDisplayPreferences
Closed

Added Backingstore, setAll and getAll methods, modified Helper Method…#14941
aaryyya wants to merge 3 commits intoJabRef:mainfrom
aaryyya:fix_NameDisplayPreferences

Conversation

@aaryyya
Copy link
Contributor

@aaryyya aaryyya commented Jan 27, 2026

User description

…s and default constructor was added

Closes #14412

Steps to test

Mandatory checks


PR Type

Enhancement


Description

  • Added default constructor and factory method to NameDisplayPreferences

  • Implemented setAll() method for copying preferences between instances

  • Refactored preference initialization to use backing store pattern

  • Removed hardcoded preference defaults from JabRefGuiPreferences

  • Integrated NameDisplayPreferences into preference reset and import workflows


Diagram Walkthrough

flowchart LR
  A["NameDisplayPreferences"] -->|"getDefault()"| B["Default Instance"]
  A -->|"setAll()"| C["Copy Preferences"]
  D["JabRefGuiPreferences"] -->|"getNameDisplayPreferencesFromBackingStore()"| E["Load from Backing Store"]
  D -->|"clear()/importPreferences()"| F["Reset/Sync Preferences"]
Loading

File Walkthrough

Relevant files
Enhancement
NameDisplayPreferences.java
Add default constructor and preference copy methods           

jabgui/src/main/java/org/jabref/gui/maintable/NameDisplayPreferences.java

  • Added private default constructor with DisplayStyle.NATBIB and
    AbbreviationStyle.LASTNAME_ONLY defaults
  • Added static getDefault() factory method for creating default
    instances
  • Added setAll() method to copy display and abbreviation styles from
    another instance
+18/-0   
JabRefGuiPreferences.java
Refactor name display preferences with backing store pattern

jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java

  • Removed hardcoded preference defaults for name display settings
    (NAMES_AS_IS, NAMES_FIRST_LAST, NAMES_NATBIB, ABBR_AUTHOR_NAMES,
    NAMES_LAST_ONLY)
  • Refactored getNameDisplayPreferences() to use
    getNameDisplayPreferencesFromBackingStore() with default instance
  • Simplified getNameAbbreviationStyle() and getNameDisplayStyle() to
    delegate to default preferences
  • Added new getNameDisplayPreferencesFromBackingStore() method to load
    preferences from backing store
  • Integrated NameDisplayPreferences into clear() and importPreferences()
    workflows
+11/-25 

@github-actions github-actions bot added the good first issue An issue intended for project-newcomers. Varies in difficulty. label Jan 27, 2026
@qodo-free-for-open-source-projects
Copy link
Contributor

qodo-free-for-open-source-projects bot commented Jan 27, 2026

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🟡
🎫 #13109
🔴 Make `org.jabref.logic.pseudonymization.Pseudonymization` available on the CLI
Provide similar CLI experience to the consistency check
Follow the implementation pattern of `org.jabref.cli.CheckConsistency` class
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-free-for-open-source-projects
Copy link
Contributor

qodo-free-for-open-source-projects bot commented Jan 27, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix loading of user preferences

Restore the logic for loading name display preferences from the backing store
inside getNameDisplayPreferencesFromBackingStore. The current implementation
incorrectly uses hardcoded defaults, ignoring any user-saved settings.

jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java [948-959]

-private NameDisplayPreferences.AbbreviationStyle getNameAbbreviationStyle() {
-    return NameDisplayPreferences.getDefault().getAbbreviationStyle();
+private NameDisplayPreferences getNameDisplayPreferencesFromBackingStore(
+        NameDisplayPreferences defaults) {
+    NameDisplayPreferences.DisplayStyle displayStyle;
+    if (getBoolean(NAMES_NATBIB)) {
+        displayStyle = NameDisplayPreferences.DisplayStyle.NATBIB;
+    } else if (getBoolean(NAMES_AS_IS)) {
+        displayStyle = NameDisplayPreferences.DisplayStyle.AS_IS;
+    } else if (getBoolean(NAMES_FIRST_LAST)) {
+        displayStyle = NameDisplayPreferences.DisplayStyle.FIRSTNAME_LASTNAME;
+    } else {
+        displayStyle = defaults.getDisplayStyle();
+    }
+
+    NameDisplayPreferences.AbbreviationStyle abbreviationStyle;
+    if (getBoolean(ABBR_AUTHOR_NAMES)) {
+        abbreviationStyle = NameDisplayPreferences.AbbreviationStyle.FULL;
+    } else if (getBoolean(NAMES_LAST_ONLY)) {
+        abbreviationStyle = NameDisplayPreferences.AbbreviationStyle.LASTNAME_ONLY;
+    } else {
+        abbreviationStyle = defaults.getAbbreviationStyle();
+    }
+
+    return new NameDisplayPreferences(displayStyle, abbreviationStyle);
 }
 
-private NameDisplayPreferences.DisplayStyle getNameDisplayStyle() {
-    return NameDisplayPreferences.getDefault().getDisplayStyle();
-}
-
-private NameDisplayPreferences getNameDisplayPreferencesFromBackingStore(
-        NameDisplayPreferences defaults) {
-    return new NameDisplayPreferences(getNameDisplayStyle(), getNameAbbreviationStyle());
-}
-
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a critical regression where user-configured name display preferences are ignored due to the refactoring, and it provides a correct fix that restores the intended functionality of loading settings from the backing store.

High
Learned
best practice
Add null parameter validation

Add null check for the 'other' parameter before accessing its methods to prevent
NullPointerException. Throw IllegalArgumentException if null is passed.

jabgui/src/main/java/org/jabref/gui/maintable/NameDisplayPreferences.java [36-39]

 public void setAll(NameDisplayPreferences other) {
+    if (other == null) {
+        throw new IllegalArgumentException("NameDisplayPreferences must not be null");
+    }
     setDisplayStyle(other.getDisplayStyle());
     setAbbreviationStyle(other.getAbbreviationStyle());
 }
  • Apply / Chat
Suggestion importance[1-10]: 5

__

Why:
Relevant best practice - Add input validation to methods that accept external data to ensure parameters are not null before processing.

Low
  • Update

@jabref-machine
Copy link
Collaborator

Your code currently does not meet JabRef's code guidelines. IntelliJ auto format covers some cases. There seem to be issues with your code style and autoformat configuration. Please reformat your code (Ctrl+Alt+L) and commit, then push.

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Jan 27, 2026
@aaryyya
Copy link
Contributor Author

aaryyya commented Jan 27, 2026

@calixtus
im here from #14765
i am trying to test my changes manually by running the gui instead im facing an error
image
is there any way to solve this and also u had suggested few changes in the pull request which i have made
please let me know if any more changes r required

@koppor
Copy link
Member

koppor commented Jan 27, 2026

git submodule update --init

is your friend

@koppor
Copy link
Member

koppor commented Jan 27, 2026

@aaryyya DO NOT OPEN A NEW PULL REQUEST AFTER EACH CHAGNE - please push your updated! PUSH TO THE EXISTING BRANCH? OK? Not sure if you understand.

@koppor
Copy link
Member

koppor commented Jan 27, 2026

This starts to be chaos. Review comments from could be #14765 (comment)

Comment on lines -954 to +949
NameDisplayPreferences.AbbreviationStyle abbreviationStyle = NameDisplayPreferences.AbbreviationStyle.NONE; // default
if (getBoolean(ABBR_AUTHOR_NAMES)) {
abbreviationStyle = NameDisplayPreferences.AbbreviationStyle.FULL;
} else if (getBoolean(NAMES_LAST_ONLY)) {
abbreviationStyle = NameDisplayPreferences.AbbreviationStyle.LASTNAME_ONLY;
}
return abbreviationStyle;
return NameDisplayPreferences.getDefault().getAbbreviationStyle();
Copy link
Member

Choose a reason for hiding this comment

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

So you basically ignore what is stored in the preferences and just always use the defaults?

Comment on lines -964 to +953
NameDisplayPreferences.DisplayStyle displayStyle = NameDisplayPreferences.DisplayStyle.LASTNAME_FIRSTNAME; // default
if (getBoolean(NAMES_NATBIB)) {
displayStyle = NameDisplayPreferences.DisplayStyle.NATBIB;
} else if (getBoolean(NAMES_AS_IS)) {
displayStyle = NameDisplayPreferences.DisplayStyle.AS_IS;
} else if (getBoolean(NAMES_FIRST_LAST)) {
displayStyle = NameDisplayPreferences.DisplayStyle.FIRSTNAME_LASTNAME;
}
return displayStyle;
return NameDisplayPreferences.getDefault().getDisplayStyle();
Copy link
Member

Choose a reason for hiding this comment

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

Nope

defaults.put(ABBR_AUTHOR_NAMES, Boolean.TRUE); // "Abbreviate names"
defaults.put(NAMES_LAST_ONLY, Boolean.TRUE); // "Show last names only"
// endregion
//
Copy link
Member

Choose a reason for hiding this comment

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

?

@aaryyya aaryyya closed this Jan 29, 2026
@aaryyya aaryyya deleted the fix_NameDisplayPreferences branch January 29, 2026 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good first issue An issue intended for project-newcomers. Varies in difficulty. Review effort 2/5 status: changes-required Pull requests that are not yet complete

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable resetting of NameDisplayPreferences

4 participants