Skip to content

Conversation

@aaryyya
Copy link
Contributor

@aaryyya aaryyya commented Dec 30, 2025

User description

Closes #14412

Steps to test

Mandatory checks


PR Type

Enhancement


Description

  • Added private constructor with default display preferences

  • Added getDefault() static method for creating default instances

  • Added setAll() method to copy preferences from another instance


Diagram Walkthrough

flowchart LR
  A["NameDisplayPreferences"] -->|"private constructor"| B["Default values"]
  A -->|"getDefault()"| C["New instance"]
  A -->|"setAll()"| D["Copy preferences"]
Loading

File Walkthrough

Relevant files
Enhancement
NameDisplayPreferences.java
Add default constructor and utility methods                           

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

  • Added private no-arg constructor that initializes with default display
    style and abbreviation style
  • Added public static getDefault() method to create instances with
    default preferences
  • Added public setAll() method to copy display and abbreviation style
    from another NameDisplayPreferences instance
+16/-0   

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

qodo-free-for-open-source-projects bot commented Dec 30, 2025

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
🔴 Add Pseudonymization functionality to the CLI
Make org.jabref.logic.pseudonymization.Pseudonymization available on the CLI
Provide similar CLI experience to the consistency check
Implement similar to 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: 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: Robust Error Handling and Edge Case Management

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

Status:
Missing null check: The setAll() method does not validate if the other parameter is null before accessing its
methods.

Referred Code
public void setAll(NameDisplayPreferences other) {
    setDisplayStyle(other.getDisplayStyle());
    setAbbreviationStyle(other.getAbbreviationStyle());
}

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:
Missing input validation: The setAll() method accepts external input without null validation, which could lead to
NullPointerException.

Referred Code
public void setAll(NameDisplayPreferences other) {
    setDisplayStyle(other.getDisplayStyle());
    setAbbreviationStyle(other.getAbbreviationStyle());
}

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 Dec 30, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
The PR is not aligned with the associated ticket

The PR modifies NameDisplayPreferences, but the linked ticket #13109 is about
adding a "Pseudonymization" feature to the CLI. This discrepancy should be
resolved by either changing the code to match the ticket or linking the PR to
the correct ticket.

Examples:

jabgui/src/main/java/org/jabref/gui/maintable/NameDisplayPreferences.java [1-64]
package org.jabref.gui.maintable;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;

public class NameDisplayPreferences {

    public enum DisplayStyle {
        NATBIB, AS_IS, FIRSTNAME_LASTNAME, LASTNAME_FIRSTNAME
    }

 ... (clipped 54 lines)

Solution Walkthrough:

Before:

// File: jabgui/src/main/java/org/jabref/gui/maintable/NameDisplayPreferences.java
public class NameDisplayPreferences {
    // ... constructor and properties

    private NameDisplayPreferences() {
        this(
                DisplayStyle.NATBIB,
                AbbreviationStyle.LASTNAME_ONLY
        );
    }

    public static NameDisplayPreferences getDefault() {
        return new NameDisplayPreferences();
    }

    public void setAll(NameDisplayPreferences other) {
        // ...
    }
}

After:

// Hypothetical new file: jabkit/src/main/java/org/jabref/cli/Pseudonymize.java
// (to align with ticket #13109)
public class Pseudonymize implements JabRefCLI.Command {

    @Override
    public String getName() {
        return "pseudonymize";
    }

    @Override
    public void execute(String[] args) throws Exception {
        // Logic for CLI-based pseudonymization
        // 1. Parse command-line arguments
        // 2. Load the BibTeX database
        // 3. Apply pseudonymization logic
        // 4. Save the modified database
    }
}
Suggestion importance[1-10]: 10

__

Why: The suggestion correctly identifies a critical discrepancy between the PR's code changes and the linked ticket's requirements, which invalidates the PR's stated purpose.

High
Possible issue
Add null check to prevent NullPointerException

In the setAll method, add a null check for the other parameter to prevent a
NullPointerException if it is null.

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

 public void setAll(NameDisplayPreferences other) {
+    java.util.Objects.requireNonNull(other);
     setDisplayStyle(other.getDisplayStyle());
     setAbbreviationStyle(other.getAbbreviationStyle());
 }
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a potential NullPointerException in the newly added setAll method and provides a standard, robust solution to prevent it.

Medium
  • Update

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

aaryyya commented Dec 31, 2025

Hey @calixtus i have made changes as suggested

@aaryyya aaryyya requested a review from calixtus December 31, 2025 06:59
@jabref-machine
Copy link
Collaborator

Your code currently does not meet JabRef's code guidelines. We use Checkstyle to identify issues. 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 "Source Code Tests / Checkstyle (pull_request)" and click on it.

In case of issues with the import order, double check that you activated Auto Import. You can trigger fixing imports by pressing Ctrl+Alt+O to trigger Optimize Imports.

Please carefully follow the setup guide for the codestyle. Afterwards, please run checkstyle locally and fix the issues, commit, and push.

@calixtus
Copy link
Member

calixtus commented Dec 31, 2025

Clear your preferences and try to run again. I expect it to fail, because getBoolean etc. looks for a value in the defaults map, which is not present in backing store with cleared preferences.
Look at other preferences prs how they did. You need to deliver the default value from your default preferences object to that method meaning you have to adapt the helper methods.

Comment on lines +1005 to +1008
if (getBoolean(NAMES_AS_IS)) {
return NameDisplayPreferences.DisplayStyle.AS_IS;
}
if (getBoolean(NAMES_FIRST_LAST)) {
Copy link
Member

Choose a reason for hiding this comment

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

Will fail with fresh install / cleared preferences. Did you try it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i will get on it and let u know

Copy link
Member

Choose a reason for hiding this comment

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

Stick to the plan. Modify the helper methods and follow the guide in the issue description.

Copy link
Member

Choose a reason for hiding this comment

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

And please test you changes manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NEW

private NameDisplayPreferences.AbbreviationStyle getNameAbbreviationStyle() {
        nameDisplayPreferences = NameDisplayPreferences.getDefault();
        return nameDisplayPreferences.getAbbreviationStyle();
    }

OLD

    private NameDisplayPreferences.AbbreviationStyle getNameAbbreviationStyle() {
        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;
    }

Hey @calixtus , since I can't use getBoolean method is this a right approach then?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I'm travelling. Back in about 12 days

@calixtus calixtus marked this pull request as draft January 1, 2026 07:34
@aaryyya aaryyya requested a review from calixtus January 6, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: preferences good first issue An issue intended for project-newcomers. Varies in difficulty. Review effort 1/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

3 participants