-
CSR
-
Resolution: Approved
-
P4
-
source
-
low
-
Further refinements to the swing generification may be needed, but the changes in this bug should address most problems.
-
Java API
-
SE
Summary
Increase source compatibility of parts of the generification of swing by using wildcards instead of Object as a bound and reverting to raw types in some instances.
Problem
After the initial generification to swing (JDK-8043550), was in a promoted build of JDK 9, feedback came in about some larger than expected source incompatibilities.
Solution
Revise some of the generification choices to provide greater source compatibility with existing swing code.
Specification
--- old/src/share/classes/javax/swing/JSlider.java 2014-08-07 16:53:58.000000000 -0700
+++ new/src/share/classes/javax/swing/JSlider.java 2014-08-07 16:53:58.000000000 -0700
@@ -797,7 +797,7 @@
* @return the <code>Dictionary</code> containing labels and
* where to draw them
*/
- public Dictionary<Integer, JComponent> getLabelTable() {
+ public Dictionary<Integer, ? extends JComponent> getLabelTable() {
/*
if ( labelTable == null && getMajorTickSpacing() > 0 ) {
setLabelTable( createStandardLabels( getMajorTickSpacing() ) );
@@ -830,8 +830,8 @@
* attribute: visualUpdate true
* description: Specifies what labels will be drawn for any given value.
*/
- public void setLabelTable( Dictionary<Integer, JComponent> labels ) {
- Dictionary<Integer, JComponent> oldTable = labelTable;
+ public void setLabelTable( Dictionary<Integer, ? extends JComponent> labels ) {
+ Dictionary<Integer, ? extends JComponent> oldTable = labelTable;
labelTable = labels;
updateLabelUIs();
firePropertyChange("labelTable", oldTable, labelTable );
--- old/src/share/classes/javax/swing/table/DefaultTableModel.java 2014-08-07 16:54:03.000000000 -0700
+++ new/src/share/classes/javax/swing/table/DefaultTableModel.java 2014-08-07 16:54:02.000000000 -0700
@@ -70,10 +70,18 @@
* The <code>Vector</code> of <code>Vectors</code> of
* <code>Object</code> values.
*/
- protected Vector<Vector<Object>> dataVector;
+ @SuppressWarnings("rawtypes")
+ protected Vector<Vector> dataVector;
/** The <code>Vector</code> of column identifiers. */
- protected Vector<Object> columnIdentifiers;
+ @SuppressWarnings("rawtypes")
+ protected Vector columnIdentifiers;
+ // Unfortunately, for greater source compatibility the inner-most
+ // Vector in the two fields above is being left raw. The Vector is
+ // read as well as written so using Vector<?> is not suitable and
+ // using Vector<Object> (without adding copying of input Vectors),
+ // would disallow existing code that used, say, a Vector<String>
+ // as an input parameter.
//
// Constructors
@@ -121,7 +129,7 @@
* @see #setDataVector
* @see #setValueAt
*/
- public DefaultTableModel(Vector<Object> columnNames, int rowCount) {
+ public DefaultTableModel(Vector<?> columnNames, int rowCount) {
setDataVector(newVector(rowCount), columnNames);
}
@@ -156,7 +164,8 @@
* @see #getDataVector
* @see #setDataVector
*/
- public DefaultTableModel(Vector<Vector<Object>> data, Vector<Object> columnNames) {
+ @SuppressWarnings("rawtypes")
+ public DefaultTableModel(Vector<? extends Vector> data, Vector<?> columnNames) {
setDataVector(data, columnNames);
}
@@ -191,7 +200,8 @@
* @see #newRowsAdded
* @see #setDataVector
*/
- public Vector<Vector<Object>> getDataVector() {
+ @SuppressWarnings("rawtypes")
+ public Vector<Vector> getDataVector() {
return dataVector;
}
@@ -219,9 +229,10 @@
* @param columnIdentifiers the names of the columns
* @see #getDataVector
*/
- public void setDataVector(Vector<Vector<Object>> dataVector,
- Vector<Object> columnIdentifiers) {
- this.dataVector = nonNullVector(dataVector);
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public void setDataVector(Vector<? extends Vector> dataVector,
+ Vector<?> columnIdentifiers) {
+ this.dataVector = nonNullVector((Vector<Vector>)dataVector);
this.columnIdentifiers = nonNullVector(columnIdentifiers);
justifyRows(0, getRowCount());
fireTableStructureChanged();
@@ -350,7 +361,7 @@
*
* @param rowData optional data of the row being added
*/
- public void addRow(Vector<Object> rowData) {
+ public void addRow(Vector<?> rowData) {
insertRow(getRowCount(), rowData);
}
@@ -374,7 +385,7 @@
* @param rowData optional data of the row being added
* @exception ArrayIndexOutOfBoundsException if the row was invalid
*/
- public void insertRow(int row, Vector<Object> rowData) {
+ public void insertRow(int row, Vector<?> rowData) {
dataVector.insertElementAt(rowData, row);
justifyRows(row, row+1);
fireTableRowsInserted(row, row);
@@ -484,7 +495,7 @@
* to zero columns
* @see #setNumRows
*/
- public void setColumnIdentifiers(Vector<Object> columnIdentifiers) {
+ public void setColumnIdentifiers(Vector<?> columnIdentifiers) {
setDataVector(dataVector, columnIdentifiers);
}
@@ -550,7 +561,8 @@
* @param columnName the identifier of the column being added
* @param columnData optional data of the column being added
*/
- public void addColumn(Object columnName, Vector<Object> columnData) {
+ @SuppressWarnings("unchecked") // Adding element to raw columnIdentifiers
+ public void addColumn(Object columnName, Vector<?> columnData) {
columnIdentifiers.addElement(columnName);
if (columnData != null) {
int columnSize = columnData.size();
--- old/src/share/classes/javax/swing/tree/TreeNode.java 2014-08-07 16:54:05.000000000 -0700
+++ new/src/share/classes/javax/swing/tree/TreeNode.java 2014-08-07 16:54:05.000000000 -0700
@@ -99,5 +99,5 @@
*
* @return the children of the receiver as an {@code Enumeration}
*/
- Enumeration<TreeNode> children();
+ Enumeration<? extends TreeNode> children();
}
--- a/src/share/classes/javax/swing/JTable.java Fri Aug 15 13:02:46 2014 +0400
+++ b/src/share/classes/javax/swing/JTable.java Fri Aug 15 11:33:13 2014 -0700
@@ -670,7 +670,8 @@
* @param rowData the data for the new table
* @param columnNames names of each column
*/
- public JTable(Vector<Vector<Object>> rowData, Vector<Object> columnNames) {
+ @SuppressWarnings("rawtypes")
+ public JTable(Vector<? extends Vector> rowData, Vector<?> columnNames) {
this(new DefaultTableModel(rowData, columnNames));
}
- csr for
-
JDK-8054360 Refine generification of javax.swing
-
- Resolved
-
- relates to
-
CCC-8043550 Fix raw and unchecked lint warnings in javax.swing.*
-
- Closed
-
-
CCC-8055254 Address source incompatability of JSlider generification
-
- Closed
-