-
Notifications
You must be signed in to change notification settings - Fork 66
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
fix!: use the same cell reference constructor in order to ensure consistency #4634
base: main
Are you sure you want to change the base?
Conversation
@@ -399,8 +401,10 @@ public void onSelectionDecreasePainted(int r, int c) { | |||
if (!SpreadsheetUtil.isCellInRange(selectedCellReference, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NULL_DEREFERENCE: object selectedCellReference
last assigned on line 398 could be null and is dereferenced by call to isCellInRange(...)
at line 401.
ℹ️ Learn about @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Command | Usage |
---|---|
@sonatype-lift ignore |
Leave out the above finding from this PR |
@sonatype-lift ignoreall |
Leave out all the existing findings from this PR |
@sonatype-lift exclude <file|issue|path|tool> |
Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file |
Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
@@ -148,7 +148,8 @@ public void captureCellRangeValues(CellRangeAddress... cellRanges) { | |||
|
|||
@Override | |||
public CellReference getSelectedCellReference() { | |||
return new CellReference(selectedCellRow, selectedcellCol); | |||
return new CellReference(spreadsheet.getActiveSheet().getSheetName(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For commands, it seems safer to use SpreadsheetCommand.getSheet()
. Currently that always delegates to Spreadsheet.getActivesheet()
, but there's a chance that the implementation might change at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in the latest version
@@ -334,7 +334,9 @@ private void fireCellValueChangeEvent(CellRangeAddress region) { | |||
for (int x = region.getFirstColumn(); x <= region | |||
.getLastColumn(); x++) { | |||
for (int y = region.getFirstRow(); y <= region.getLastRow(); y++) { | |||
cells.add(new CellReference(y, x)); | |||
cells.add(new CellReference( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main issue with the overall change to include spreadsheet names into the cell references is that if a developer is already using cell references without the sheet name, the comparison will now fail. And that's quite easy to achieve, as new CellReference("A2")
is a lot easier to use than the other alternatives that include the sheet name. It's very likely a breaking change.
We could consider adding both types of references (with and without sheet name) to the events. For example, for cell value change events we could modify the logic here:
Lines 796 to 799 in 245d39b
private void fireCellValueChangeEvent(Set<CellReference> changedCells) { | |
spreadsheet | |
.fireEvent(new CellValueChangeEvent(spreadsheet, changedCells)); | |
} |
To something like:
private void fireCellValueChangeEvent(Set<CellReference> changedCells) {
List<CellReference> cellRefsWithSheetName = changedCells
.stream()
.filter(ref -> ref.getSheetName() != null)
.toList();
cellRefsWithSheetName.forEach(ref -> {
CellReference refWithoutSheetName = new CellReference(ref.getRow(), ref.getCol());
changedCells.add(refWithoutSheetName);
});
spreadsheet
.fireEvent(new CellValueChangeEvent(spreadsheet, changedCells));
}
The downside would be that a change to a single cell will report two changes in the event. Though that might be the lesser evil than relying on which CellReference
constructor someone is using.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in the latest version
…aluechangelistener-for-anything-else-than-text-input
…uechangelistener-for-anything-else-than-text-input
…uechangelistener-for-anything-else-than-text-input
…tener-for-anything-else-than-text-input' of https://github.com/vaadin/flow-components into 4588-spreadsheet-does-not-trigger-addcellvaluechangelistener-for-anything-else-than-text-input
…uechangelistener-for-anything-else-than-text-input
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
…uechangelistener-for-anything-else-than-text-input
…uechangelistener-for-anything-else-than-text-input
…uechangelistener-for-anything-else-than-text-input
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
As we are not aware of any users having problems due to this issue, perhaps it would be better to wait until the next major as it will introduce some breaking changes? |
Added to the v25 breaking changes list to be revisited before v25. |
Description
In Apache POI,
CellReference
has multiple constructors. In the version that Vaadin V8 used, the constructorCellReference(Cell cell)
did not use the sheet name from theCell
object. However, while having the same signature, this constructor started using the sheet name in the new versions. This creates inconsistencies when checking equality forCellReference
s since we use different constructors in various locations.Several options were discussed, including:
Set.contains
usages, however the set will have duplicates and any size comparison would be broken.Set.contains
checks to be updated to include the sheet names. This might also be somewhat inconvenient. Using the constructors without sheet names (e.g "B2", "C3") is easier and the sheet name might be expected to determined from the context.CellSet
that handlescontains
behaviour inside. This will be a breaking change for users that use the set directly or use otherSet
API.This PR goes with this option. For the API:
size()
is presentcontains(...)
is presentgetCells()
is used to get the actual set of cells and perform any other operationsNote that currently,
CellSet
only supports cells from the same sheet. If necessary, another internal set can be initialized with all the combinations to provide accurate and fast response tocontains(...)
calls.Fixes #4588
Type of change
Checklist