Refactor JournalAbbreviationRepository class to use on-disk maps #12606
Trag Code Review
Reviewed files details
Details
[2025-03-17T20:46:33.054Z] code review started
[2025-03-17T20:46:33.055Z] owner: JabRef
[2025-03-17T20:46:33.055Z] repo: jabref
[2025-03-17T20:46:33.055Z] repoUrl: https://github.com/JabRef/jabref
[2025-03-17T20:46:33.055Z] author: marwanemad07
[2025-03-17T20:46:33.055Z] listing pull request files
[2025-03-17T20:46:33.432Z] file count: 3
[2025-03-17T20:46:34.175Z] pro user privilege applied
[2025-03-17T20:46:34.175Z] getting project rules
[2025-03-17T20:46:38.874Z] model: claude-3-5-sonnet-20240620
[2025-03-17T20:46:38.874Z] on rule review mode: true
[2025-03-17T20:46:38.874Z] glob ignore:
[2025-03-17T20:46:38.874Z] pull number: 12606
[2025-03-17T20:46:38.874Z] projectId: 885262de-6ea4-406f-ab33-0a18e077aaf9
[2025-03-17T20:46:52.875Z] file: src/main/java/org/jabref/cli/JournalListMvGenerator.java
[2025-03-17T20:46:52.875Z] reading file blob
[2025-03-17T20:47:08.874Z] filteredRules: 1. If a method has JavaDoc and code of the method has changed, the JavaDoc has to be updated accordingly. No need to add JavaDoc for "trivial" exceptions
2. If code in org.jabref.model or org.jabref.logic has been changed, tests need to be adapted or updated accordingly
3. The code should follow the fail fast principle by immediately handling invalid states and returning early instead of nesting logic inside else branches.
Example:
Bad:
if (path.isEmpty()) {
return false;
} else {
// other code
}
Good:
if (path.isEmpty()) {
return false;
}
// other code
4. Assertion statements must not include the message parameter - the method name should already convey the expected behavior.
5. The pull request title should contain a short title of the issue fixed (or what the PR adresses) and not just "Fix issue xyz"
6. The "Mandatory checks" are Markdown TODOs. They should be formatted as that. Wrong: - [ x]
. Either - [ ]
or - [x]
.
7. New methods (and new classes) should follow the Single-responsibility principle (SRP).
8. There should be JavaDoc for complex methods.
9. "Magic" numbers or strings should be constants - or at least have a Java comment. Exception: JavaFX height and widths.
10. Avoid code duplication
11. Use modern Java best practices, such as Arguments.of() instead of new Object[] in JUnit tests, to improve readability and maintainability.
12. Exceptions should be used for exceptional states - not for normal control flow
13. Follow the principles of "Effective Java"
14. In JabRef, localized strings are done using Localization.lang("string")
. More information at https://devdocs.jabref.org/code-howtos/localization.html.
15. No use of Java SWING, only JavaFX is allowed as UI technology
16. @DisplayName for tests should only be used if absolutely necessary: The method name itself should be comprehensive enough.
17. Comments should add new information (e.g. reasoning of the code). It should not be plainly derived fro the code itself.
Example for trivail comments:
// Commit the staged changes
RevCommit commit = git.commit()
- Instead of
Files.createTempDirectory
@TempDir
JUnit5 annotation should be used. - Do not catch the general java java.lang.Exception. Catch specific exeptions only
- Avoid exclamation marks at the end of a sentence. They are more for screaming. Use a dot to end the sentence.
- All labels and texts should be sentence case (and not title case)
- New public methods should not return
null
. They should make use ofjava.util.Optional
. In casenull
really needs to be used, the JSpecify annotations must be used. - Use "BibTeX" as spelling for bibtex
- New strings should be consistent to other strings. They should also be grouped semantically together.
- Existings strings should be reused instead of introducing slightly different strings
- Comments on/above methods should be JavaDoc.not simple Java comments //. Three /// are OK (because this is Java23 and later)
- The CHANGELOG.md entry should be for end users (and not programmers).
- User dialogs should have proper button labels: NOT yes/no/cancel, but indicating the action which happens when pressing the button
- GUI code should only be a gateway to code in org.jabref.logic. More complex code regarding non-GUI operations should go into org.jabref.logic. Think of layerd archicture.
null
should never be passed to a method (except it has the same name).- Do not add extra blank lines in CHANGELOG.md
- Remove commented code. (To keep a history of changes git was made for.)
- Do not use Objects.requireNonNull. Use JSpecify
@NonNull
annotation if needs be. - Never throw unchecked exceptions (e.g., throw new RuntimeException)
- When adding JavaDoc, the text should be non-trivial.
Example for trivial JavaDoc:
* @param backupDir the backup directory
* @param dbfile the database file
* @throws IOException if an I/O error occurs
* @throws GitAPIException if a Git API error occurs
- Code should not be reformatted only because of syntax. There need to be new statements added if reformatting.
- If
@TempDir
is used, there is no need to clean it up
Example for wrong code:
@AfterEach
void tearDown() throws IOException {
FileUtils.cleanDirectory(tempDir.toFile());
}
- Assert the contents of objects (assertEquals), not checking for some Boolean conditions (assertTrue/assertFalse)
Example for wrong code:
assertTrue(
entry.getFiles().stream()
.anyMatch(file -> file.getLink().equals(newFile.getFileName().toString()) ||
file.getLink().endsWith("/" + newFile.getFileName().toString()))
);
- No "new Thread()", use "org.jabref.logic.util.BackgroundTask" and its "executeWith"
- try blocks shoud cover as less statements as possible (and not whole methods)
- use "throws Exception" in the method declaration instead of try-catch and fail/log/...
- When creating a new BibEntry object, instead of
setField
,withField
methods should be used. - In case Java comments are added, they should match the code following. They should be a high-level summary or guidance of the following code (and not some reandom text or just re-stating the obvious)
- Use the methods of java.util.Optional.
ifPresent
.
NOT
Optional<String> resolved = bibEntry.getResolvedFieldOrAlias(...);
String value = resolved.orElse("");
doSomething(value)
Following is fine:
Optional<String> resolved = bibEntry.getResolvedFieldOrAlias(...);
resolved.ifPresent(value -> doSomething(value));
- If the java.util.Optional is really present, use use
get()
(and notorElse("")
) - Use Java Text blocks (""") for multiline string constants
- Use compiled patterns (Pattern.compile)
NOT: listOfNames.matches(".\s{2,}.")
BUT: private final static PATTERN = ... - and athen PATTERN.matches(...)
48. Use placeholders if variance is in localizaiton:
BAD: Localization.lang("Current JabRef version") + ": " + buildInfo.version);
GOOD: Localization.lang("Current JabRef version: %0", buildInfo.version);
[2025-03-17T20:47:21.448Z] filtering out non-relevant issues
[2025-03-17T20:47:21.449Z] broad list of issues found
[2025-03-17T20:47:21.449Z] score: 7
[2025-03-17T20:47:21.449Z] Reason: Multiple map operations are performed without checking for null values from getter methods. This could lead to NullPointerException if any of the getter methods return null.
[2025-03-17T20:47:21.449Z] filtering out low importance issues
[2025-03-17T20:47:21.449Z] --------------------------------
[2025-03-17T20:47:21.449Z] writing comments to pr...
[2025-03-17T20:47:21.449Z] file: src/main/java/org/jabref/logic/journals/Abbreviation.java
[2025-03-17T20:47:21.449Z] reading file blob
[2025-03-17T20:47:32.444Z] filteredRules: 1. If a method has JavaDoc and code of the method has changed, the JavaDoc has to be updated accordingly. No need to add JavaDoc for "trivial" exceptions
2. If code in org.jabref.model or org.jabref.logic has been changed, tests need to be adapted or updated accordingly
3. The code should follow the fail fast principle by immediately handling invalid states and returning early instead of nesting logic inside else branches.
Example:
Bad:
if (path.isEmpty()) {
return false;
} else {
// other code
}
Good:
if (path.isEmpty()) {
return false;
}
// other code
4. Assertion statements must not include the message parameter - the method name should already convey the expected behavior.
5. The pull request title should contain a short title of the issue fixed (or what the PR adresses) and not just "Fix issue xyz"
6. The "Mandatory checks" are Markdown TODOs. They should be formatted as that. Wrong: - [ x]
. Either - [ ]
or - [x]
.
7. New methods (and new classes) should follow the Single-responsibility principle (SRP).
8. There should be JavaDoc for complex methods.
9. "Magic" numbers or strings should be constants - or at least have a Java comment. Exception: JavaFX height and widths.
10. Avoid code duplication
11. Use modern Java best practices, such as Arguments.of() instead of new Object[] in JUnit tests, to improve readability and maintainability.
12. Exceptions should be used for exceptional states - not for normal control flow
13. Follow the principles of "Effective Java"
14. In JabRef, localized strings are done using Localization.lang("string")
. More information at https://devdocs.jabref.org/code-howtos/localization.html.
15. No use of Java SWING, only JavaFX is allowed as UI technology
16. @DisplayName for tests should only be used if absolutely necessary: The method name itself should be comprehensive enough.
17. Comments should add new information (e.g. reasoning of the code). It should not be plainly derived fro the code itself.
Example for trivail comments:
// Commit the staged changes
RevCommit commit = git.commit()
- Instead of
Files.createTempDirectory
@TempDir
JUnit5 annotation should be used. - Do not catch the general java java.lang.Exception. Catch specific exeptions only
- Avoid exclamation marks at the end of a sentence. They are more for screaming. Use a dot to end the sentence.
- All labels and texts should be sentence case (and not title case)
- New public methods should not return
null
. They should make use ofjava.util.Optional
. In casenull
really needs to be used, the JSpecify annotations must be used. - Use "BibTeX" as spelling for bibtex
- New strings should be consistent to other strings. They should also be grouped semantically together.
- Existings strings should be reused instead of introducing slightly different strings
- Comments on/above methods should be JavaDoc.not simple Java comments //. Three /// are OK (because this is Java23 and later)
- The CHANGELOG.md entry should be for end users (and not programmers).
- User dialogs should have proper button labels: NOT yes/no/cancel, but indicating the action which happens when pressing the button
- GUI code should only be a gateway to code in org.jabref.logic. More complex code regarding non-GUI operations should go into org.jabref.logic. Think of layerd archicture.
null
should never be passed to a method (except it has the same name).- Do not add extra blank lines in CHANGELOG.md
- Remove commented code. (To keep a history of changes git was made for.)
- Do not use Objects.requireNonNull. Use JSpecify
@NonNull
annotation if needs be. - Never throw unchecked exceptions (e.g., throw new RuntimeException)
- When adding JavaDoc, the text should be non-trivial.
Example for trivial JavaDoc:
* @param backupDir the backup directory
* @param dbfile the database file
* @throws IOException if an I/O error occurs
* @throws GitAPIException if a Git API error occurs
- Code should not be reformatted only because of syntax. There need to be new statements added if reformatting.
- If
@TempDir
is used, there is no need to clean it up
Example for wrong code:
@AfterEach
void tearDown() throws IOException {
FileUtils.cleanDirectory(tempDir.toFile());
}
- Assert the contents of objects (assertEquals), not checking for some Boolean conditions (assertTrue/assertFalse)
Example for wrong code:
assertTrue(
entry.getFiles().stream()
.anyMatch(file -> file.getLink().equals(newFile.getFileName().toString()) ||
file.getLink().endsWith("/" + newFile.getFileName().toString()))
);
- No "new Thread()", use "org.jabref.logic.util.BackgroundTask" and its "executeWith"
- try blocks shoud cover as less statements as possible (and not whole methods)
- use "throws Exception" in the method declaration instead of try-catch and fail/log/...
- When creating a new BibEntry object, instead of
setField
,withField
methods should be used. - In case Java comments are added, they should match the code following. They should be a high-level summary or guidance of the following code (and not some reandom text or just re-stating the obvious)
- Use the methods of java.util.Optional.
ifPresent
.
NOT
Optional<String> resolved = bibEntry.getResolvedFieldOrAlias(...);
String value = resolved.orElse("");
doSomething(value)
Following is fine:
Optional<String> resolved = bibEntry.getResolvedFieldOrAlias(...);
resolved.ifPresent(value -> doSomething(value));
- If the java.util.Optional is really present, use use
get()
(and notorElse("")
) - Use Java Text blocks (""") for multiline string constants
- Use compiled patterns (Pattern.compile)
NOT: listOfNames.matches(".\s{2,}.")
BUT: private final static PATTERN = ... - and athen PATTERN.matches(...)
48. Use placeholders if variance is in localizaiton:
BAD: Localization.lang("Current JabRef version") + ": " + buildInfo.version);
GOOD: Localization.lang("Current JabRef version: %0", buildInfo.version);
[2025-03-17T20:47:39.275Z] filtering out non-relevant issues
[2025-03-17T20:47:39.475Z] broad list of issues found
[2025-03-17T20:47:39.475Z] filtering out low importance issues
[2025-03-17T20:47:39.475Z] --------------------------------
[2025-03-17T20:47:39.475Z] writing comments to pr...
[2025-03-17T20:47:39.475Z] file: src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java
[2025-03-17T20:47:39.475Z] reading file blob
[2025-03-17T20:47:58.474Z] filteredRules: 1. If a method has JavaDoc and code of the method has changed, the JavaDoc has to be updated accordingly. No need to add JavaDoc for "trivial" exceptions
2. If code in org.jabref.model or org.jabref.logic has been changed, tests need to be adapted or updated accordingly
3. The code should follow the fail fast principle by immediately handling invalid states and returning early instead of nesting logic inside else branches.
Example:
Bad:
if (path.isEmpty()) {
return false;
} else {
// other code
}
Good:
if (path.isEmpty()) {
return false;
}
// other code
4. Assertion statements must not include the message parameter - the method name should already convey the expected behavior.
5. The pull request title should contain a short title of the issue fixed (or what the PR adresses) and not just "Fix issue xyz"
6. The "Mandatory checks" are Markdown TODOs. They should be formatted as that. Wrong: - [ x]
. Either - [ ]
or - [x]
.
7. New methods (and new classes) should follow the Single-responsibility principle (SRP).
8. There should be JavaDoc for complex methods.
9. "Magic" numbers or strings should be constants - or at least have a Java comment. Exception: JavaFX height and widths.
10. Avoid code duplication
11. Use modern Java best practices, such as Arguments.of() instead of new Object[] in JUnit tests, to improve readability and maintainability.
12. Exceptions should be used for exceptional states - not for normal control flow
13. Follow the principles of "Effective Java"
14. In JabRef, localized strings are done using Localization.lang("string")
. More information at https://devdocs.jabref.org/code-howtos/localization.html.
15. No use of Java SWING, only JavaFX is allowed as UI technology
16. @DisplayName for tests should only be used if absolutely necessary: The method name itself should be comprehensive enough.
17. Comments should add new information (e.g. reasoning of the code). It should not be plainly derived fro the code itself.
Example for trivail comments:
// Commit the staged changes
RevCommit commit = git.commit()
- Instead of
Files.createTempDirectory
@TempDir
JUnit5 annotation should be used. - Do not catch the general java java.lang.Exception. Catch specific exeptions only
- Avoid exclamation marks at the end of a sentence. They are more for screaming. Use a dot to end the sentence.
- All labels and texts should be sentence case (and not title case)
- New public methods should not return
null
. They should make use ofjava.util.Optional
. In casenull
really needs to be used, the JSpecify annotations must be used. - Use "BibTeX" as spelling for bibtex
- New strings should be consistent to other strings. They should also be grouped semantically together.
- Existings strings should be reused instead of introducing slightly different strings
- Comments on/above methods should be JavaDoc.not simple Java comments //. Three /// are OK (because this is Java23 and later)
- The CHANGELOG.md entry should be for end users (and not programmers).
- User dialogs should have proper button labels: NOT yes/no/cancel, but indicating the action which happens when pressing the button
- GUI code should only be a gateway to code in org.jabref.logic. More complex code regarding non-GUI operations should go into org.jabref.logic. Think of layerd archicture.
null
should never be passed to a method (except it has the same name).- Do not add extra blank lines in CHANGELOG.md
- Remove commented code. (To keep a history of changes git was made for.)
- Do not use Objects.requireNonNull. Use JSpecify
@NonNull
annotation if needs be. - Never throw unchecked exceptions (e.g., throw new RuntimeException)
- When adding JavaDoc, the text should be non-trivial.
Example for trivial JavaDoc:
* @param backupDir the backup directory
* @param dbfile the database file
* @throws IOException if an I/O error occurs
* @throws GitAPIException if a Git API error occurs
- Code should not be reformatted only because of syntax. There need to be new statements added if reformatting.
- If
@TempDir
is used, there is no need to clean it up
Example for wrong code:
@AfterEach
void tearDown() throws IOException {
FileUtils.cleanDirectory(tempDir.toFile());
}
- Assert the contents of objects (assertEquals), not checking for some Boolean conditions (assertTrue/assertFalse)
Example for wrong code:
assertTrue(
entry.getFiles().stream()
.anyMatch(file -> file.getLink().equals(newFile.getFileName().toString()) ||
file.getLink().endsWith("/" + newFile.getFileName().toString()))
);
- No "new Thread()", use "org.jabref.logic.util.BackgroundTask" and its "executeWith"
- try blocks shoud cover as less statements as possible (and not whole methods)
- use "throws Exception" in the method declaration instead of try-catch and fail/log/...
- When creating a new BibEntry object, instead of
setField
,withField
methods should be used. - In case Java comments are added, they should match the code following. They should be a high-level summary or guidance of the following code (and not some reandom text or just re-stating the obvious)
- Use the methods of java.util.Optional.
ifPresent
.
NOT
Optional<String> resolved = bibEntry.getResolvedFieldOrAlias(...);
String value = resolved.orElse("");
doSomething(value)
Following is fine:
Optional<String> resolved = bibEntry.getResolvedFieldOrAlias(...);
resolved.ifPresent(value -> doSomething(value));
- If the java.util.Optional is really present, use use
get()
(and notorElse("")
) - Use Java Text blocks (""") for multiline string constants
- Use compiled patterns (Pattern.compile)
NOT: listOfNames.matches(".\s{2,}.")
BUT: private final static PATTERN = ... - and athen PATTERN.matches(...)
48. Use placeholders if variance is in localizaiton:
BAD: Localization.lang("Current JabRef version") + ": " + buildInfo.version);
GOOD: Localization.lang("Current JabRef version: %0", buildInfo.version);
[2025-03-17T20:48:11.841Z] filtering out non-relevant issues
[2025-03-17T20:48:12.175Z] broad list of issues found
[2025-03-17T20:48:12.378Z] score: 8
[2025-03-17T20:48:12.378Z] Reason: The MVStore instance is not properly closed, which could lead to resource leaks. The class should implement AutoCloseable to ensure proper resource management.
[2025-03-17T20:48:12.378Z] score: 7
[2025-03-17T20:48:12.378Z] Reason: The MVStore is opened without any error handling for file access issues or corruption. This could lead to runtime failures without proper error propagation.
[2025-03-17T20:48:12.378Z] score: 6
[2025-03-17T20:48:12.378Z] Reason: Constants are exposed as public for external use in JournalMvGenerator.java, which violates encapsulation. Should use proper accessor methods instead.
[2025-03-17T20:48:12.378Z] score: 5
[2025-03-17T20:48:12.378Z] Reason: Multiple nested null checks create unnecessary complexity. Should use Optional.ofNullable().or() chain to simplify the logic and improve readability.
[2025-03-17T20:48:12.378Z] filtering out low importance issues
[2025-03-17T20:48:12.378Z] --------------------------------
[2025-03-17T20:48:12.378Z] writing comments to pr...
[2025-03-17T20:48:12.378Z] files scanned: 3
[2025-03-17T20:48:12.379Z] lines scanned: 207
[2025-03-17T20:48:12.379Z] rules for project: 48
[2025-03-17T20:48:12.379Z] issues caught by your rules: 0