Fix: suppress WARN for empty or blank column name in MainTableColumnModel#parse()#15576
Fix: suppress WARN for empty or blank column name in MainTableColumnModel#parse()#15576Afra0704 wants to merge 6 commits intoJabRef:mainfrom
Conversation
Review Summary by QodoSuppress warning for empty or blank column names in MainTableColumnModel
WalkthroughsDescription• Add null/blank check in MainTableColumnModel.parse() to prevent warnings • Return default NORMALFIELD type for empty or whitespace-only column names • Add unit tests for empty and blank string inputs • Update CHANGELOG documenting the fix Diagramflowchart LR
A["parse() receives empty/blank string"] -->|null or isBlank check| B["Return NORMALFIELD with empty qualifier"]
C["parse() receives valid string"] -->|normal flow| D["Split and process column name"]
B --> E["No WARN message logged"]
D --> F["Type determined from string"]
File Changes1. jabgui/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java
|
Code Review by Qodo
1.
|
|
Thanks for the review! I've addressed both issues:
|
| columnPreferences.getColumns().forEach(column -> columns.add(createColumn(column))); | ||
| columnPreferences.getColumns().stream() | ||
| .map(this::createColumn) | ||
| .filter(Objects::nonNull) |
There was a problem hiding this comment.
This filter call is new. Why was it added?
There was a problem hiding this comment.
createColumn() returns null for NORMALFIELD with blank qualifier.
Without this filter, the null would be added to the column list and
cause a NullPointerException later.
There was a problem hiding this comment.
Okay but what I'm wondering: why was this not an issue before?
There was a problem hiding this comment.
This was originally pointed out by Qodo AI, which suggested that createColumn() may return null for this case and that filtering it out would be a reasonable defensive measure.
That said, I'm not entirely sure why this did not cause problems before. My guess is that the previous behavior did not exercise this path in practice, or that the resulting null entry was not dereferenced later.
So the filter may not be strictly necessary to fix the original WARN itself, but I kept it as a defensive fix to avoid returning null entries from createColumns(). If you'd prefer to keep this PR focused only on the WARN, I can remove it.
There was a problem hiding this comment.
Okay, so null is not returned right now, this is just a defensive measure?
Probably fine, but I will let the others decide. But that is good to know, because at first I thought we now throw a NPE but did not before, which sounds like a regression and is not expected behavior.
The Behavior should be the same as before, just without the warning. Thats why I asked.
There was a problem hiding this comment.
If I remember correctly, in default circumstances columnPreferences.getColumns always delivered a list of valid values or an empty list. So here Objects::nonNull is not allowed, we opted for compile time null safety with JSpecify annotations and nullaway in ADRs 52 and 53. Solution is not to filter, but to annotate createColumn accordingly.
There was a problem hiding this comment.
Thank you for the guidance! I have removed the filter and annotated createColumn()
with @Nullable instead, following JabRef's JSpecify approach.
There was a problem hiding this comment.
No this is wrong. This is guaranteed to be nonnull. Always an ArrayList.
There was a problem hiding this comment.
createColumn (without the s) must be annotated and if neccessary modified. Maybe a good place to do some Data Oriented Programming?
There was a problem hiding this comment.
Sorry for the mistake! I have moved the @Nullable annotation to createColumn()
instead of createColumns().
There was a problem hiding this comment.
createColumn (without the s) must be annotated and if neccessary modified. Maybe a good place to do some Data Oriented Programming?
Maybe this would escalate this too much.
Nevertheless, by marking it Nullable this will result in a compiler warning for now, which is ok, until we eventually fix all nullaway warnings. But this issue is tracked now.
|
Your pull request conflicts with the target branch. Please merge with your code. For a step-by-step guide to resolve merge conflicts, see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line. |
Related issues and pull requests
Closes #15571
PR Description
When
MainTableColumnModel.parse()was called with an empty or blank string (from stored preferences), it triggered aWARN: Column type '' is unknown.message repeatedly. This fix adds a guard clause inparse()to return a defaultNORMALFIELDcolumn model early when the input is empty or blank, preventing the unnecessary warning.isBlank()is used instead ofisEmpty()to also handle whitespace-only strings, which are equally invalid as column names.Steps to test
MainTableColumnModelTestemptyStringShouldReturnNormalFieldWithEmptyQualifierandblankStringShouldReturnNormalFieldWithEmptyQualifierboth passWARN: Column type '' is unknown.should appear in the consoleChecklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)