Skip to content

Commit f9e80ab

Browse files
EcljpseB0Tjukzi
authored andcommitted
ViewerCell: eager NPE, final members #177
Do not reuse ViewerCell instance - that only caused trouble and was clearly forbidden by org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerCell). Instead let the GC do his job. Declaring the constants final formally requires API change. But it was never intended that the constants could be changed. #177
1 parent 15e993f commit f9e80ab

File tree

9 files changed

+41
-353
lines changed

9 files changed

+41
-353
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<component id="org.eclipse.jface" version="2">
3+
<resource path="src/org/eclipse/jface/viewers/ViewerCell.java" type="org.eclipse.jface.viewers.ViewerCell">
4+
<filter comment="constants should be final" id="388100214">
5+
<message_arguments>
6+
<message_argument value="org.eclipse.jface.viewers.ViewerCell"/>
7+
<message_argument value="ABOVE"/>
8+
</message_arguments>
9+
</filter>
10+
<filter comment="constants should be final" id="388100214">
11+
<message_arguments>
12+
<message_argument value="org.eclipse.jface.viewers.ViewerCell"/>
13+
<message_argument value="BELOW"/>
14+
</message_arguments>
15+
</filter>
16+
<filter comment="constants should be final" id="388100214">
17+
<message_arguments>
18+
<message_argument value="org.eclipse.jface.viewers.ViewerCell"/>
19+
<message_argument value="LEFT"/>
20+
</message_arguments>
21+
</filter>
22+
<filter comment="constants should be final" id="388100214">
23+
<message_arguments>
24+
<message_argument value="org.eclipse.jface.viewers.ViewerCell"/>
25+
<message_argument value="RIGHT"/>
26+
</message_arguments>
27+
</filter>
28+
</resource>
29+
</component>

bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTableViewer.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -405,19 +405,10 @@ protected void doUpdateItem(Widget widget, Object element, boolean fullMap) {
405405
}
406406

407407
ViewerColumn columnViewer = getViewerColumn(column);
408-
ViewerCell cellToUpdate = updateCell(viewerRowFromItem,
409-
column, element);
410-
411-
// If the control is virtual, we cannot use the cached cell object. See bug 188663.
412-
if (isVirtual) {
413-
cellToUpdate = new ViewerCell(cellToUpdate.getViewerRow(), cellToUpdate.getColumnIndex(), element);
414-
}
408+
ViewerCell cellToUpdate = new ViewerCell(viewerRowFromItem, column, element);
415409

416410
columnViewer.refresh(cellToUpdate);
417411

418-
// clear cell (see bug 201280)
419-
updateCell(null, 0, null);
420-
421412
// As it is possible for user code to run the event
422413
// loop check here.
423414
if (item.isDisposed()) {

bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -977,19 +977,10 @@ protected void doUpdateItem(final Item item, Object element) {
977977
}
978978

979979
ViewerColumn columnViewer = getViewerColumn(column);
980-
ViewerCell cellToUpdate = updateCell(viewerRowFromItem, column,
981-
element);
982-
983-
// If the control is virtual, we cannot use the cached cell object. See bug 188663.
984-
if (isVirtual) {
985-
cellToUpdate = new ViewerCell(cellToUpdate.getViewerRow(), cellToUpdate.getColumnIndex(), element);
986-
}
980+
ViewerCell cellToUpdate = new ViewerCell(viewerRowFromItem, column, element);
987981

988982
columnViewer.refresh(cellToUpdate);
989983

990-
// clear cell (see bug 201280)
991-
updateCell(null, 0, null);
992-
993984
// As it is possible for user code to run the event
994985
// loop check here.
995986
if (item.isDisposed()) {

bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnViewer.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ public abstract class ColumnViewer extends StructuredViewer {
6464

6565
private String[] columnProperties;
6666

67-
/**
68-
* The cell is a cached viewer cell used for refreshing.
69-
*/
70-
private ViewerCell cell = new ViewerCell(null, 0, null);
71-
7267
private ColumnViewerEditor viewerEditor;
7368

7469
private boolean busy;
@@ -307,19 +302,6 @@ private ViewerColumn createViewerColumn(Widget columnOwner,
307302
return column;
308303
}
309304

310-
/**
311-
* Update the cached cell object with the given row and column.
312-
*
313-
* @param rowItem
314-
* @param column
315-
* @return ViewerCell
316-
*/
317-
/* package */ViewerCell updateCell(ViewerRow rowItem, int column,
318-
Object element) {
319-
cell.update(rowItem, column, element);
320-
return cell;
321-
}
322-
323305
/**
324306
* Returns the {@link Item} at the given widget-relative coordinates, or
325307
* <code>null</code> if there is no item at the given coordinates.

bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerCell.java

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,31 @@
3434
*
3535
*/
3636
public class ViewerCell {
37-
private int columnIndex;
37+
private final int columnIndex;
3838

39-
private ViewerRow row;
39+
private final ViewerRow row;
4040

41-
private Object element;
41+
private final Object element;
4242

4343
/**
4444
* Constant denoting the cell above current one (value is 1).
4545
*/
46-
public static int ABOVE = 1;
46+
public static final int ABOVE = 1;
4747

4848
/**
4949
* Constant denoting the cell below current one (value is 2).
5050
*/
51-
public static int BELOW = 1 << 1;
51+
public static final int BELOW = 1 << 1;
5252

5353
/**
5454
* Constant denoting the cell to the left of the current one (value is 4).
5555
*/
56-
public static int LEFT = 1 << 2;
56+
public static final int LEFT = 1 << 2;
5757

5858
/**
5959
* Constant denoting the cell to the right of the current one (value is 8).
6060
*/
61-
public static int RIGHT = 1 << 3;
61+
public static final int RIGHT = 1 << 3;
6262

6363
/**
6464
* Create a new instance of the receiver on the row.
@@ -67,6 +67,7 @@ public class ViewerCell {
6767
* @param columnIndex
6868
*/
6969
ViewerCell(ViewerRow row, int columnIndex, Object element) {
70+
Objects.requireNonNull(row);
7071
this.row = row;
7172
this.columnIndex = columnIndex;
7273
this.element = element;
@@ -200,29 +201,6 @@ public StyleRange[] getStyleRanges() {
200201
return row.getStyleRanges(columnIndex);
201202
}
202203

203-
/**
204-
* Set the columnIndex.
205-
*
206-
* @param column the column index to set
207-
*/
208-
void setColumn(int column) {
209-
columnIndex = column;
210-
211-
}
212-
213-
/**
214-
* Set the row to rowItem and the columnIndex to column.
215-
*
216-
* @param rowItem the row item to set
217-
* @param column the column index to set
218-
* @param element the element to set
219-
*/
220-
void update(ViewerRow rowItem, int column, Object element) {
221-
row = rowItem;
222-
columnIndex = column;
223-
this.element = element;
224-
}
225-
226204
/**
227205
* Return the item for the receiver.
228206
*

tests/org.eclipse.jface.tests/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Bundle-SymbolicName: org.eclipse.jface.tests
5-
Bundle-Version: 1.4.200.qualifier
5+
Bundle-Version: 1.4.300.qualifier
66
Automatic-Module-Name: org.eclipse.jface.tests
77
Bundle-RequiredExecutionEnvironment: JavaSE-17
88
Require-Bundle: org.junit;bundle-version="4.12.0",

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/AllViewersTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
CComboViewerTest.class, TreeViewerComparatorTest.class, ListViewerComparatorTest.class,
2929
TableViewerComparatorTest.class, Bug138608Test.class, ComboViewerComparerTest.class,
3030
ListViewerRefreshTest.class, Bug200558Test.class, Bug201002TableViewerTest.class, Bug201002TreeViewerTest.class,
31-
Bug200337TableViewerTest.class, Bug203657TreeViewerTest.class, Bug203657TableViewerTest.class,
31+
Bug200337TableViewerTest.class, //
3232
Bug205700TreeViewerTest.class, Bug180504TableViewerTest.class, Bug180504TreeViewerTest.class,
3333
Bug256889TableViewerTest.class, Bug287765Test.class, Bug242231Test.class, StyledStringBuilderTest.class,
3434
TreeViewerWithLimitTest.class, TreeViewerWithLimitCompatibilityTest.class, TableViewerWithLimitTest.class,

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/Bug203657TableViewerTest.java

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)