-
Notifications
You must be signed in to change notification settings - Fork 505
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
8235491: Tree/TableView: implementation of isSelected(int) violates contract #839
Changes from 2 commits
a87821c
82f0db7
784833d
2b76edd
fcdf223
74e8b15
be4825a
6267a0e
de8cd41
cb3a809
ad3c70b
7fa2588
9de5858
cc7953b
7646693
35247bc
9ad9352
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
|
@@ -172,7 +172,7 @@ private TablePosition pos(int row, TableColumn<String,?> col) { | |
assertFalse(model.isSelected(1, col0)); | ||
assertFalse(model.isSelected(3, col0)); | ||
assertFalse(cells(model), model.isSelected(3, null)); | ||
assertFalse(model.isSelected(3)); | ||
assertTrue(model.isSelected(3)); | ||
assertEquals(1, model.getSelectedCells().size()); | ||
} | ||
|
||
Comment on lines
-175
to
180
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have tests isSelected(index) for all combinations of single/multiple/cellSelection? If not, now might be a good time to add them :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a very good point! |
||
|
@@ -185,7 +185,7 @@ private TablePosition pos(int row, TableColumn<String,?> col) { | |
assertFalse(model.isSelected(1, col0)); | ||
assertFalse(model.isSelected(3, col0)); | ||
assertFalse(cells(model), model.isSelected(3, null)); | ||
assertFalse(model.isSelected(3)); | ||
assertTrue(model.isSelected(3)); | ||
assertEquals(1, model.getSelectedCells().size()); | ||
} | ||
|
||
|
@@ -852,4 +852,24 @@ private TablePosition pos(int row, TableColumn<String,?> col) { | |
model.clearSelection(2); | ||
model.getSelectedItems().removeListener(listener); | ||
} | ||
|
||
/** | ||
* Analysing failing tests when fixing JDK-8219720. | ||
* | ||
* Suspect: isSelected(int row) violates contract. | ||
* | ||
* @see #selectRowWhenInSingleCellSelectionMode() | ||
* @see #selectRowWhenInSingleCellSelectionMode2() | ||
*/ | ||
@Test | ||
public void testSelectRowWhenInSingleCellSelectionModeIsSelected() { | ||
model.setSelectionMode(SelectionMode.SINGLE); | ||
model.setCellSelectionEnabled(true); | ||
model.select(3); | ||
// test against contract | ||
assertEquals("selected index", 3, model.getSelectedIndex()); | ||
assertTrue("contained in selected indices", model.getSelectedIndices().contains(3)); | ||
// test against spec | ||
assertEquals("is selected index", model.getSelectedIndices().contains(3), model.isSelected(3)); | ||
} | ||
} |
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.
Code Style : Why to create a local variable with the same name as method it gets its value from?
In this case changing to
if (isCellSelectionEnabled())
condition check looks simple enough.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.
thank you for your comments, Ajit! below are responses, please let me know if you agree or not:
javadoc for TableSelectionModel.isSelected(int, TablecolumnBase) already describes the logic:
`
/**
*/
public abstract boolean isSelected(int row, TableColumnBase<T,?> column);
`
TreeTableView.TreeTableViewSelectionModel extends TableSelectionModel, so the changes affect both.
good point, fixed.
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.
Yes. I am aware of this documentation. I was thinking of making it clear for the users if they see their application breaks due to this change. I see that you have captured this in "Compatibility Impact" section of the CSR.
I see that there are overridden methods
public boolean isSelected(int index)
andpublic boolean isSelected(int row, TableColumnBase<TreeItem<S>,?> column)
in classTreeTableViewArrayListSelectionModel
present in TreeTableView.java. Hence, I think that the change that you have made inTableView.java - isSelected(int index)
method should also be made inTreeTableView.java - isSelected(int index)
as well.Thanks!
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.
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.
@aghaisas
If any application breaks, it's its own fault: they coded against the implementation of TableXXSelectionModels which was (incorrectly)
isSelected(int) == isSelected(int, null)
.That might be due to the specification mess, though:
SelectionModel.isSelected(int)
was incorrectly arguing with api on MultipleSelectionModel, that is Is functionally equivalent to calling getSelectedIndices().contains(index)MultipleSelectionModel.isSelected(int)
which has no specialized specMultipleSelectionModelBase.isSelected(int)
fulfilling the constraint but also without spec.To clean this up completely, we could also change the of MultipleSelectionModel and move the old
isSelected(int) == getSelectedIndices().contains(int)
into the spec of its isSelected. Probably could be done in a follow-up issue (or added to one of the open doc errors around selection models).What do you think?
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.
I like this idea. Either filing a new bug or fold into an existing one seems fine.