From a5e2b3c3fbfad3801e2f6f1a09bed7eb1ba7cbb3 Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Tue, 22 Jul 2014 17:10:50 +0400 Subject: [PATCH 001/215] 8032864: [macosx] sigsegv (0Xb) Being Generated When Starting JDev With Voiceover Running Reviewed-by: anthony, serb --- jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m b/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m index e0de79524e8..1b3ec43a9fe 100644 --- a/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m +++ b/jdk/src/macosx/native/sun/awt/JavaComponentAccessibility.m @@ -1108,7 +1108,10 @@ static NSObject *sAttributeNamesLOCK = nil; JNIEnv *env = [ThreadUtilities getJNIEnv]; id value = nil; + NSWindow* hostWindow = [[self->fView window] retain]; jobject focused = JNFCallStaticObjectMethod(env, jm_getFocusOwner, fComponent); // AWT_THREADING Safe (AWTRunLoop) + [hostWindow release]; + if (focused != NULL) { if (JNFIsInstanceOf(env, focused, &sjc_Accessible)) { value = [JavaComponentAccessibility createWithAccessible:focused withEnv:env withView:fView]; From b1798855c043f71587ee51cd65f21ce1cd9ff723 Mon Sep 17 00:00:00 2001 From: Alexander Scherbatiy Date: Tue, 22 Jul 2014 17:17:05 +0400 Subject: [PATCH 002/215] 8038937: Validate fields on Swing classes deserialization Reviewed-by: serb, pchelko --- .../share/classes/javax/swing/ImageIcon.java | 23 +++- .../share/classes/javax/swing/JComponent.java | 27 ++++- .../classes/javax/swing/JFileChooser.java | 69 ++++++++++-- jdk/src/share/classes/javax/swing/JLayer.java | 14 ++- .../classes/javax/swing/JOptionPane.java | 51 ++++++--- .../share/classes/javax/swing/JPopupMenu.java | 15 ++- .../classes/javax/swing/JTabbedPane.java | 39 +++++-- jdk/src/share/classes/javax/swing/JTable.java | 102 ++++++++++++++++-- jdk/src/share/classes/javax/swing/JTree.java | 44 +++++++- .../swing/LegacyGlueFocusTraversalPolicy.java | 18 +++- jdk/src/share/classes/javax/swing/Timer.java | 39 ++++--- .../javax/swing/text/AbstractDocument.java | 7 +- .../javax/swing/text/DefaultCaret.java | 25 ++++- .../swing/text/DefaultStyledDocument.java | 5 +- .../javax/swing/text/JTextComponent.java | 41 ++++++- .../javax/swing/text/MaskFormatter.java | 10 +- .../javax/swing/text/StyleContext.java | 16 ++- .../classes/javax/swing/text/html/CSS.java | 7 +- .../swing/tree/DefaultMutableTreeNode.java | 15 ++- .../swing/tree/DefaultTreeCellEditor.java | 20 +++- .../javax/swing/tree/DefaultTreeModel.java | 14 ++- .../swing/tree/DefaultTreeSelectionModel.java | 49 +++++++-- 22 files changed, 550 insertions(+), 100 deletions(-) diff --git a/jdk/src/share/classes/javax/swing/ImageIcon.java b/jdk/src/share/classes/javax/swing/ImageIcon.java index 8f7812e5919..564e173c5c8 100644 --- a/jdk/src/share/classes/javax/swing/ImageIcon.java +++ b/jdk/src/share/classes/javax/swing/ImageIcon.java @@ -490,12 +490,33 @@ public class ImageIcon implements Icon, Serializable, Accessible { private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { - s.defaultReadObject(); + ObjectInputStream.GetField f = s.readFields(); + + imageObserver = (ImageObserver) f.get("imageObserver", null); + description = (String) f.get("description", null); + width = f.get("width", -1); + height = f.get("height", -1); + accessibleContext = (AccessibleImageIcon) f.get("accessibleContext", null); int w = s.readInt(); int h = s.readInt(); int[] pixels = (int[])(s.readObject()); + if (pixels == null && (w != -1 || h != -1)) { + throw new IllegalStateException("Inconsistent width and height" + + " for null image [" + w + ", " + h + "]"); + } + + if (pixels != null && (w < 0 || h < 0)) { + throw new IllegalStateException("Inconsistent width and height" + + " for image [" + w + ", " + h + "]"); + } + + if (w != getIconWidth() || h != getIconHeight()) { + throw new IllegalStateException("Inconsistent width and height" + + " for image [" + w + ", " + h + "]"); + } + if (pixels != null) { Toolkit tk = Toolkit.getDefaultToolkit(); ColorModel cm = ColorModel.getRGBdefault(); diff --git a/jdk/src/share/classes/javax/swing/JComponent.java b/jdk/src/share/classes/javax/swing/JComponent.java index 765610ebbad..17cbf60100b 100644 --- a/jdk/src/share/classes/javax/swing/JComponent.java +++ b/jdk/src/share/classes/javax/swing/JComponent.java @@ -1888,7 +1888,7 @@ public abstract class JComponent extends Container implements Serializable, * description: The preferred vertical alignment of the component. */ public void setAlignmentY(float alignmentY) { - this.alignmentY = alignmentY > 1.0f ? 1.0f : alignmentY < 0.0f ? 0.0f : alignmentY; + this.alignmentY = validateAlignment(alignmentY); isAlignmentYSet = true; } @@ -1917,10 +1917,14 @@ public abstract class JComponent extends Container implements Serializable, * description: The preferred horizontal alignment of the component. */ public void setAlignmentX(float alignmentX) { - this.alignmentX = alignmentX > 1.0f ? 1.0f : alignmentX < 0.0f ? 0.0f : alignmentX; + this.alignmentX = validateAlignment(alignmentX); isAlignmentXSet = true; } + private float validateAlignment(float alignment) { + return alignment > 1.0f ? 1.0f : alignment < 0.0f ? 0.0f : alignment; + } + /** * Sets the input verifier for this component. * @@ -5514,7 +5518,24 @@ public abstract class JComponent extends Container implements Serializable, private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { - s.defaultReadObject(); + ObjectInputStream.GetField f = s.readFields(); + + isAlignmentXSet = f.get("isAlignmentXSet", false); + alignmentX = validateAlignment(f.get("alignmentX", 0f)); + isAlignmentYSet = f.get("isAlignmentYSet", false); + alignmentY = validateAlignment(f.get("alignmentY", 0f)); + listenerList = (EventListenerList) f.get("listenerList", null); + vetoableChangeSupport = (VetoableChangeSupport) f.get("vetoableChangeSupport", null); + autoscrolls = f.get("autoscrolls", false); + border = (Border) f.get("border", null); + flags = f.get("flags", 0); + inputVerifier = (InputVerifier) f.get("inputVerifier", null); + verifyInputWhenFocusTarget = f.get("verifyInputWhenFocusTarget", false); + popupMenu = (JPopupMenu) f.get("popupMenu", null); + focusInputMap = (InputMap) f.get("focusInputMap", null); + ancestorInputMap = (InputMap) f.get("ancestorInputMap", null); + windowInputMap = (ComponentInputMap) f.get("windowInputMap", null); + actionMap = (ActionMap) f.get("actionMap", null); /* If there's no ReadObjectCallback for this stream yet, that is, if * this is the first call to JComponent.readObject() for this diff --git a/jdk/src/share/classes/javax/swing/JFileChooser.java b/jdk/src/share/classes/javax/swing/JFileChooser.java index bf690ddbb5b..1edf4943357 100644 --- a/jdk/src/share/classes/javax/swing/JFileChooser.java +++ b/jdk/src/share/classes/javax/swing/JFileChooser.java @@ -50,6 +50,8 @@ import java.awt.Toolkit; import java.awt.event.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; import java.lang.ref.WeakReference; /** @@ -460,10 +462,14 @@ public class JFileChooser extends JComponent implements Accessible { * bound: false */ public void setDragEnabled(boolean b) { + checkDragEnabled(b); + dragEnabled = b; + } + + private static void checkDragEnabled(boolean b) { if (b && GraphicsEnvironment.isHeadless()) { throw new HeadlessException(); } - dragEnabled = b; } /** @@ -949,9 +955,7 @@ public class JFileChooser extends JComponent implements Accessible { if(this.dialogType == dialogType) { return; } - if(!(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG || dialogType == CUSTOM_DIALOG)) { - throw new IllegalArgumentException("Incorrect Dialog Type: " + dialogType); - } + checkDialogType(dialogType); int oldValue = this.dialogType; this.dialogType = dialogType; if(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG) { @@ -960,6 +964,14 @@ public class JFileChooser extends JComponent implements Accessible { firePropertyChange(DIALOG_TYPE_CHANGED_PROPERTY, oldValue, dialogType); } + private static void checkDialogType(int dialogType) { + if (!(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG + || dialogType == CUSTOM_DIALOG)) { + throw new IllegalArgumentException( + "Incorrect Dialog Type: " + dialogType); + } + } + /** * Sets the string that goes in the JFileChooser window's * title bar. @@ -1349,12 +1361,17 @@ public class JFileChooser extends JComponent implements Accessible { return; } - if ((mode == FILES_ONLY) || (mode == DIRECTORIES_ONLY) || (mode == FILES_AND_DIRECTORIES)) { + checkFileSelectionMode(mode); int oldValue = fileSelectionMode; fileSelectionMode = mode; firePropertyChange(FILE_SELECTION_MODE_CHANGED_PROPERTY, oldValue, fileSelectionMode); - } else { - throw new IllegalArgumentException("Incorrect Mode for file selection: " + mode); + } + + private static void checkFileSelectionMode(int mode) { + if ((mode != FILES_ONLY) && (mode != DIRECTORIES_ONLY) + && (mode != FILES_AND_DIRECTORIES)) { + throw new IllegalArgumentException( + "Incorrect Mode for file selection: " + mode); } } @@ -1901,7 +1918,43 @@ public class JFileChooser extends JComponent implements Accessible { */ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { - in.defaultReadObject(); + ObjectInputStream.GetField f = in.readFields(); + + dialogTitle = (String) f.get("dialogTitle", null); + approveButtonText = (String) f.get("approveButtonText", null); + approveButtonToolTipText = + (String) f.get("approveButtonToolTipText", null); + approveButtonMnemonic = f.get("approveButtonMnemonic", 0); + @SuppressWarnings("unchecked") + Vector newFilters = (Vector) f.get("filters", null); + if (newFilters == null) { + throw new InvalidObjectException("Null filters"); + } + filters = newFilters; + dialog = (JDialog) f.get("dialog", null); + int newDialogType = f.get("dialogType", OPEN_DIALOG); + checkDialogType(newDialogType); + dialogType = newDialogType; + returnValue = f.get("returnValue", 0); + accessory = (JComponent) f.get("accessory", null); + fileView = (FileView) f.get("fileView", null); + controlsShown = f.get("controlsShown", false); + useFileHiding = f.get("useFileHiding", false); + int newFileSelectionMode = f.get("fileSelectionMode", FILES_ONLY); + checkFileSelectionMode(newFileSelectionMode); + fileSelectionMode = newFileSelectionMode; + multiSelectionEnabled = f.get("multiSelectionEnabled", false); + useAcceptAllFileFilter = f.get("useAcceptAllFileFilter", false); + boolean newDragEnabled = f.get("dragEnabled", false); + checkDragEnabled(newDragEnabled); + dragEnabled = newDragEnabled; + fileFilter = (FileFilter) f.get("fileFilter", null); + fileSystemView = (FileSystemView) f.get("fileSystemView", null); + currentDirectory = (File) f.get("currentDirectory", null); + selectedFile = (File) f.get("selectedFile", null); + selectedFiles = (File[]) f.get("selectedFiles", null); + accessibleContext = (AccessibleContext) f.get("accessibleContext", null); + installShowFilesListener(); } diff --git a/jdk/src/share/classes/javax/swing/JLayer.java b/jdk/src/share/classes/javax/swing/JLayer.java index 57bccae7ec6..7f374d88385 100644 --- a/jdk/src/share/classes/javax/swing/JLayer.java +++ b/jdk/src/share/classes/javax/swing/JLayer.java @@ -648,13 +648,19 @@ public final class JLayer private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { - s.defaultReadObject(); - if (layerUI != null) { - setUI(layerUI); - } + ObjectInputStream.GetField f = s.readFields(); + + view = (V) f.get("view", null); + glassPane = (JPanel) f.get("glassPane", null); + eventMask = f.get("eventMask", 0l); if (eventMask != 0) { eventController.updateAWTEventListener(0, eventMask); } + @SuppressWarnings("unchecked") + LayerUI newLayerUI = (LayerUI) f.get("layerUI", null); + if (newLayerUI != null) { + setUI(newLayerUI); + } } /** diff --git a/jdk/src/share/classes/javax/swing/JOptionPane.java b/jdk/src/share/classes/javax/swing/JOptionPane.java index b3d52fc5274..413b3cfab73 100644 --- a/jdk/src/share/classes/javax/swing/JOptionPane.java +++ b/jdk/src/share/classes/javax/swing/JOptionPane.java @@ -43,13 +43,10 @@ import java.awt.event.WindowEvent; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.io.IOException; +import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Vector; import javax.swing.plaf.OptionPaneUI; import javax.swing.event.InternalFrameEvent; @@ -2055,15 +2052,22 @@ public class JOptionPane extends JComponent implements Accessible * description: The option pane's message type. */ public void setMessageType(int newType) { + checkMessageType(newType); + int oldType = messageType; + messageType = newType; + firePropertyChange(MESSAGE_TYPE_PROPERTY, oldType, messageType); + } + + private static void checkMessageType(int newType){ if(newType != ERROR_MESSAGE && newType != INFORMATION_MESSAGE && newType != WARNING_MESSAGE && newType != QUESTION_MESSAGE && newType != PLAIN_MESSAGE) - throw new RuntimeException("JOptionPane: type must be one of JOptionPane.ERROR_MESSAGE, JOptionPane.INFORMATION_MESSAGE, JOptionPane.WARNING_MESSAGE, JOptionPane.QUESTION_MESSAGE or JOptionPane.PLAIN_MESSAGE"); - - int oldType = messageType; - - messageType = newType; - firePropertyChange(MESSAGE_TYPE_PROPERTY, oldType, messageType); + throw new RuntimeException("JOptionPane: type must be one of" + + " JOptionPane.ERROR_MESSAGE," + + " JOptionPane.INFORMATION_MESSAGE," + + " JOptionPane.WARNING_MESSAGE," + + " JOptionPane.QUESTION_MESSAGE" + + " or JOptionPane.PLAIN_MESSAGE"); } /** @@ -2097,16 +2101,23 @@ public class JOptionPane extends JComponent implements Accessible * description: The option pane's option type. */ public void setOptionType(int newType) { - if(newType != DEFAULT_OPTION && newType != YES_NO_OPTION && - newType != YES_NO_CANCEL_OPTION && newType != OK_CANCEL_OPTION) - throw new RuntimeException("JOptionPane: option type must be one of JOptionPane.DEFAULT_OPTION, JOptionPane.YES_NO_OPTION, JOptionPane.YES_NO_CANCEL_OPTION or JOptionPane.OK_CANCEL_OPTION"); - + checkOptionType(newType); int oldType = optionType; - optionType = newType; firePropertyChange(OPTION_TYPE_PROPERTY, oldType, optionType); } + private static void checkOptionType(int newType) { + if (newType != DEFAULT_OPTION && newType != YES_NO_OPTION + && newType != YES_NO_CANCEL_OPTION + && newType != OK_CANCEL_OPTION) { + throw new RuntimeException("JOptionPane: option type must be one of" + + " JOptionPane.DEFAULT_OPTION, JOptionPane.YES_NO_OPTION," + + " JOptionPane.YES_NO_CANCEL_OPTION" + + " or JOptionPane.OK_CANCEL_OPTION"); + } + } + /** * Returns the type of options that are displayed. * @@ -2385,7 +2396,15 @@ public class JOptionPane extends JComponent implements Accessible private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { - s.defaultReadObject(); + ObjectInputStream.GetField f = s.readFields(); + + int newMessageType = f.get("messageType", 0); + checkMessageType(newMessageType); + messageType = newMessageType; + int newOptionType = f.get("optionType", 0); + checkOptionType(newOptionType); + optionType = newOptionType; + wantsInput = f.get("wantsInput", false); Vector values = (Vector)s.readObject(); int indexCounter = 0; diff --git a/jdk/src/share/classes/javax/swing/JPopupMenu.java b/jdk/src/share/classes/javax/swing/JPopupMenu.java index ca00144b774..89311ba1228 100644 --- a/jdk/src/share/classes/javax/swing/JPopupMenu.java +++ b/jdk/src/share/classes/javax/swing/JPopupMenu.java @@ -1345,7 +1345,20 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { // implements javax.swing.MenuElement private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { - s.defaultReadObject(); + ObjectInputStream.GetField f = s.readFields(); + + int newDesiredLocationX = f.get("desiredLocationX", 0); + int newDesiredLocationY = f.get("desiredLocationY", 0); + Point p = adjustPopupLocationToFitScreen( + newDesiredLocationX, newDesiredLocationY); + desiredLocationX = p.x; + desiredLocationY = p.y; + + label = (String) f.get("label", null); + paintBorder = f.get("paintBorder", false); + margin = (Insets) f.get("margin", null); + lightWeightPopup = f.get("lightWeightPopup", false); + selectionModel = (SingleSelectionModel) f.get("selectionModel", null); Vector values = (Vector)s.readObject(); int indexCounter = 0; diff --git a/jdk/src/share/classes/javax/swing/JTabbedPane.java b/jdk/src/share/classes/javax/swing/JTabbedPane.java index 96c050529fe..ffde325f8d8 100644 --- a/jdk/src/share/classes/javax/swing/JTabbedPane.java +++ b/jdk/src/share/classes/javax/swing/JTabbedPane.java @@ -495,10 +495,7 @@ public class JTabbedPane extends JComponent * */ public void setTabPlacement(int tabPlacement) { - if (tabPlacement != TOP && tabPlacement != LEFT && - tabPlacement != BOTTOM && tabPlacement != RIGHT) { - throw new IllegalArgumentException("illegal tab placement: must be TOP, BOTTOM, LEFT, or RIGHT"); - } + checkTabPlacement(tabPlacement); if (this.tabPlacement != tabPlacement) { int oldValue = this.tabPlacement; this.tabPlacement = tabPlacement; @@ -508,6 +505,14 @@ public class JTabbedPane extends JComponent } } + private static void checkTabPlacement(int tabPlacement) { + if (tabPlacement != TOP && tabPlacement != LEFT && + tabPlacement != BOTTOM && tabPlacement != RIGHT) { + throw new IllegalArgumentException("illegal tab placement:" + + " must be TOP, BOTTOM, LEFT, or RIGHT"); + } + } + /** * Returns the policy used by the tabbedpane to layout the tabs when all the * tabs will not fit within a single run. @@ -551,9 +556,7 @@ public class JTabbedPane extends JComponent * */ public void setTabLayoutPolicy(int tabLayoutPolicy) { - if (tabLayoutPolicy != WRAP_TAB_LAYOUT && tabLayoutPolicy != SCROLL_TAB_LAYOUT) { - throw new IllegalArgumentException("illegal tab layout policy: must be WRAP_TAB_LAYOUT or SCROLL_TAB_LAYOUT"); - } + checkTabLayoutPolicy(tabLayoutPolicy); if (this.tabLayoutPolicy != tabLayoutPolicy) { int oldValue = this.tabLayoutPolicy; this.tabLayoutPolicy = tabLayoutPolicy; @@ -563,6 +566,14 @@ public class JTabbedPane extends JComponent } } + private static void checkTabLayoutPolicy(int tabLayoutPolicy) { + if (tabLayoutPolicy != WRAP_TAB_LAYOUT + && tabLayoutPolicy != SCROLL_TAB_LAYOUT) { + throw new IllegalArgumentException("illegal tab layout policy:" + + " must be WRAP_TAB_LAYOUT or SCROLL_TAB_LAYOUT"); + } + } + /** * Returns the currently selected index for this tabbedpane. * Returns -1 if there is no currently selected tab. @@ -1816,7 +1827,19 @@ public class JTabbedPane extends JComponent private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { - s.defaultReadObject(); + ObjectInputStream.GetField f = s.readFields(); + + int newTabPlacement = f.get("tabPlacement", TOP); + checkTabPlacement(newTabPlacement); + tabPlacement = newTabPlacement; + int newTabLayoutPolicy = f.get("tabLayoutPolicy", 0); + checkTabLayoutPolicy(newTabLayoutPolicy); + tabLayoutPolicy = newTabLayoutPolicy; + model = (SingleSelectionModel) f.get("model", null); + haveRegistered = f.get("haveRegistered", false); + changeListener = (ChangeListener) f.get("changeListener", null); + visComp = (Component) f.get("visComp", null); + if ((ui != null) && (getUIClassID().equals(uiClassID))) { ui.installUI(this); } diff --git a/jdk/src/share/classes/javax/swing/JTable.java b/jdk/src/share/classes/javax/swing/JTable.java index a4f30ac33a5..d88dbed9985 100644 --- a/jdk/src/share/classes/javax/swing/JTable.java +++ b/jdk/src/share/classes/javax/swing/JTable.java @@ -37,6 +37,7 @@ import java.beans.*; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.io.IOException; +import java.io.InvalidObjectException; import javax.accessibility.*; @@ -1203,11 +1204,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * AUTO_RESIZE_ALL_COLUMNS JTable.AUTO_RESIZE_ALL_COLUMNS */ public void setAutoResizeMode(int mode) { - if ((mode == AUTO_RESIZE_OFF) || - (mode == AUTO_RESIZE_NEXT_COLUMN) || - (mode == AUTO_RESIZE_SUBSEQUENT_COLUMNS) || - (mode == AUTO_RESIZE_LAST_COLUMN) || - (mode == AUTO_RESIZE_ALL_COLUMNS)) { + if (isValidAutoResizeMode(mode)) { int old = autoResizeMode; autoResizeMode = mode; resizeAndRepaint(); @@ -1218,6 +1215,14 @@ public class JTable extends JComponent implements TableModelListener, Scrollable } } + private static boolean isValidAutoResizeMode(int mode) { + return (mode == AUTO_RESIZE_OFF) + || (mode == AUTO_RESIZE_NEXT_COLUMN) + || (mode == AUTO_RESIZE_SUBSEQUENT_COLUMNS) + || (mode == AUTO_RESIZE_LAST_COLUMN) + || (mode == AUTO_RESIZE_ALL_COLUMNS); + } + /** * Returns the auto resize mode of the table. The default mode * is AUTO_RESIZE_SUBSEQUENT_COLUMNS. @@ -1439,10 +1444,14 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * bound: false */ public void setDragEnabled(boolean b) { + checkDragEnabled(b); + dragEnabled = b; + } + + private void checkDragEnabled(boolean b) { if (b && GraphicsEnvironment.isHeadless()) { throw new HeadlessException(); } - dragEnabled = b; } /** @@ -1489,6 +1498,11 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @since 1.6 */ public final void setDropMode(DropMode dropMode) { + checkDropMode(dropMode); + this.dropMode = dropMode; + } + + private static void checkDropMode(DropMode dropMode) { if (dropMode != null) { switch (dropMode) { case USE_SELECTION: @@ -1499,14 +1513,12 @@ public class JTable extends JComponent implements TableModelListener, Scrollable case ON_OR_INSERT: case ON_OR_INSERT_ROWS: case ON_OR_INSERT_COLS: - this.dropMode = dropMode; return; } } - - throw new IllegalArgumentException(dropMode + ": Unsupported drop mode for table"); + throw new IllegalArgumentException(dropMode + + ": Unsupported drop mode for table"); } - /** * Returns the drop mode for this component. * @@ -5865,7 +5877,75 @@ public class JTable extends JComponent implements TableModelListener, Scrollable private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { - s.defaultReadObject(); + ObjectInputStream.GetField f = s.readFields(); + + TableModel newDataModel = (TableModel) f.get("dataModel", null); + if (newDataModel == null) { + throw new InvalidObjectException("Null dataModel"); + } + dataModel = newDataModel; + + TableColumnModel newColumnModel = (TableColumnModel) f.get("columnModel", null); + if (newColumnModel == null) { + throw new InvalidObjectException("Null columnModel"); + } + columnModel = newColumnModel; + + ListSelectionModel newSelectionModel = (ListSelectionModel) f.get("selectionModel", null); + if (newSelectionModel == null) { + throw new InvalidObjectException("Null selectionModel"); + } + selectionModel = newSelectionModel; + + tableHeader = (JTableHeader) f.get("tableHeader", null); + int newRowHeight = f.get("rowHeight", 0); + if (newRowHeight <= 0) { + throw new InvalidObjectException("Row height less than 1"); + } + rowHeight = newRowHeight; + + rowMargin = f.get("rowMargin", 0); + Color newGridColor = (Color) f.get("gridColor", null); + if (newGridColor == null) { + throw new InvalidObjectException("Null gridColor"); + } + gridColor = newGridColor; + + showHorizontalLines = f.get("showHorizontalLines", false); + showVerticalLines = f.get("showVerticalLines", false); + int newAutoResizeMode = f.get("autoResizeMode", 0); + if (!isValidAutoResizeMode(newAutoResizeMode)) { + throw new InvalidObjectException("autoResizeMode is not valid"); + } + autoResizeMode = newAutoResizeMode; + autoCreateColumnsFromModel = f.get("autoCreateColumnsFromModel", false); + preferredViewportSize = (Dimension) f.get("preferredViewportSize", null); + rowSelectionAllowed = f.get("rowSelectionAllowed", false); + cellSelectionEnabled = f.get("cellSelectionEnabled", false); + selectionForeground = (Color) f.get("selectionForeground", null); + selectionBackground = (Color) f.get("selectionBackground", null); + rowModel = (SizeSequence) f.get("rowModel", null); + + boolean newDragEnabled = f.get("dragEnabled", false); + checkDragEnabled(newDragEnabled); + dragEnabled = newDragEnabled; + + surrendersFocusOnKeystroke = f.get("surrendersFocusOnKeystroke", false); + editorRemover = (PropertyChangeListener) f.get("editorRemover", null); + columnSelectionAdjusting = f.get("columnSelectionAdjusting", false); + rowSelectionAdjusting = f.get("rowSelectionAdjusting", false); + printError = (Throwable) f.get("printError", null); + isRowHeightSet = f.get("isRowHeightSet", false); + updateSelectionOnSort = f.get("updateSelectionOnSort", false); + ignoreSortChange = f.get("ignoreSortChange", false); + sorterChanged = f.get("sorterChanged", false); + autoCreateRowSorter = f.get("autoCreateRowSorter", false); + fillsViewportHeight = f.get("fillsViewportHeight", false); + DropMode newDropMode = (DropMode) f.get("dropMode", + DropMode.USE_SELECTION); + checkDropMode(newDropMode); + dropMode = newDropMode; + if ((ui != null) && (getUIClassID().equals(uiClassID))) { ui.installUI(this); } diff --git a/jdk/src/share/classes/javax/swing/JTree.java b/jdk/src/share/classes/javax/swing/JTree.java index 3188156e347..6d50f6f653a 100644 --- a/jdk/src/share/classes/javax/swing/JTree.java +++ b/jdk/src/share/classes/javax/swing/JTree.java @@ -1216,10 +1216,14 @@ public class JTree extends JComponent implements Scrollable, Accessible * bound: false */ public void setDragEnabled(boolean b) { + checkDragEnabled(b); + dragEnabled = b; + } + + private static void checkDragEnabled(boolean b) { if (b && GraphicsEnvironment.isHeadless()) { throw new HeadlessException(); } - dragEnabled = b; } /** @@ -1262,18 +1266,23 @@ public class JTree extends JComponent implements Scrollable, Accessible * @since 1.6 */ public final void setDropMode(DropMode dropMode) { + checkDropMode(dropMode); + this.dropMode = dropMode; + } + + private static void checkDropMode(DropMode dropMode) { if (dropMode != null) { switch (dropMode) { case USE_SELECTION: case ON: case INSERT: case ON_OR_INSERT: - this.dropMode = dropMode; return; } } - throw new IllegalArgumentException(dropMode + ": Unsupported drop mode for tree"); + throw new IllegalArgumentException(dropMode + + ": Unsupported drop mode for tree"); } /** @@ -3089,7 +3098,34 @@ public class JTree extends JComponent implements Scrollable, Accessible private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { - s.defaultReadObject(); + ObjectInputStream.GetField f = s.readFields(); + + rootVisible = f.get("rootVisible", false); + rowHeight = f.get("rowHeight", 0); + rowHeightSet = f.get("rowHeightSet", false); + showsRootHandles = f.get("showsRootHandles", false); + showsRootHandlesSet = f.get("showsRootHandlesSet", false); + editable = f.get("editable", false); + largeModel = f.get("largeModel", false); + visibleRowCount = f.get("visibleRowCount", 0); + invokesStopCellEditing = f.get("invokesStopCellEditing", false); + scrollsOnExpand = f.get("scrollsOnExpand", false); + scrollsOnExpandSet = f.get("scrollsOnExpandSet", false); + toggleClickCount = f.get("toggleClickCount", 0); + leadPath = (TreePath) f.get("leadPath", null); + anchorPath = (TreePath) f.get("anchorPath", null); + expandsSelectedPaths = f.get("expandsSelectedPaths", false); + settingUI = f.get("settingUI", false); + boolean newDragEnabled = f.get("dragEnabled", false); + checkDragEnabled(newDragEnabled); + dragEnabled = newDragEnabled; + DropMode newDropMode = (DropMode) f.get("dropMode", + DropMode.USE_SELECTION); + checkDropMode(newDropMode); + dropMode = newDropMode; + + expandRow = f.get("expandRow", -1); + dropTimer = (TreeTimer) f.get("dropTimer", null); // Create an instance of expanded state. diff --git a/jdk/src/share/classes/javax/swing/LegacyGlueFocusTraversalPolicy.java b/jdk/src/share/classes/javax/swing/LegacyGlueFocusTraversalPolicy.java index de33d4c4dae..ac366ca8df6 100644 --- a/jdk/src/share/classes/javax/swing/LegacyGlueFocusTraversalPolicy.java +++ b/jdk/src/share/classes/javax/swing/LegacyGlueFocusTraversalPolicy.java @@ -194,7 +194,23 @@ final class LegacyGlueFocusTraversalPolicy extends FocusTraversalPolicy private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { - in.defaultReadObject(); + ObjectInputStream.GetField f = in.readFields(); + + @SuppressWarnings("unchecked") + HashMap newForwardMap = + (HashMap ) f.get("forwardMap", null); + if (newForwardMap == null) { + throw new InvalidObjectException("Null forwardMap"); + } + forwardMap = newForwardMap; + @SuppressWarnings("unchecked") + HashMap newBackwardMap = + (HashMap) f.get("backwardMap", null); + if (newBackwardMap == null) { + throw new InvalidObjectException("Null backwardMap"); + } + backwardMap = newBackwardMap; + delegatePolicy = (FocusTraversalPolicy)in.readObject(); delegateManager = (DefaultFocusManager)in.readObject(); } diff --git a/jdk/src/share/classes/javax/swing/Timer.java b/jdk/src/share/classes/javax/swing/Timer.java index 6caced7dd8d..ffaa9d53b3c 100644 --- a/jdk/src/share/classes/javax/swing/Timer.java +++ b/jdk/src/share/classes/javax/swing/Timer.java @@ -401,14 +401,15 @@ public class Timer implements Serializable * @see #setInitialDelay */ public void setDelay(int delay) { - if (delay < 0) { - throw new IllegalArgumentException("Invalid delay: " + delay); - } - else { + checkDelay(delay, "Invalid delay: "); this.delay = delay; } - } + private static void checkDelay(int delay, String message) { + if (delay < 0) { + throw new IllegalArgumentException(message + delay); + } + } /** * Returns the delay, in milliseconds, @@ -435,14 +436,9 @@ public class Timer implements Serializable * @see #setDelay */ public void setInitialDelay(int initialDelay) { - if (initialDelay < 0) { - throw new IllegalArgumentException("Invalid initial delay: " + - initialDelay); - } - else { + checkDelay(initialDelay, "Invalid initial delay: "); this.initialDelay = initialDelay; } - } /** @@ -638,7 +634,26 @@ public class Timer implements Serializable throws ClassNotFoundException, IOException { this.acc = AccessController.getContext(); - in.defaultReadObject(); + ObjectInputStream.GetField f = in.readFields(); + + EventListenerList newListenerList = (EventListenerList) + f.get("listenerList", null); + if (newListenerList == null) { + throw new InvalidObjectException("Null listenerList"); + } + listenerList = newListenerList; + + int newInitialDelay = f.get("initialDelay", 0); + checkDelay(newInitialDelay, "Invalid initial delay: "); + initialDelay = newInitialDelay; + + int newDelay = f.get("delay", 0); + checkDelay(newDelay, "Invalid delay: "); + delay = newDelay; + + repeats = f.get("repeats", false); + coalesce = f.get("coalesce", false); + actionCommand = (String) f.get("actionCommand", null); } /* diff --git a/jdk/src/share/classes/javax/swing/text/AbstractDocument.java b/jdk/src/share/classes/javax/swing/text/AbstractDocument.java index 111ab923a85..4c11836c112 100644 --- a/jdk/src/share/classes/javax/swing/text/AbstractDocument.java +++ b/jdk/src/share/classes/javax/swing/text/AbstractDocument.java @@ -1429,8 +1429,13 @@ public abstract class AbstractDocument implements Document, Serializable { private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { - s.defaultReadObject(); + ObjectInputStream.GetField f = s.readFields(); + + documentProperties = (Dictionary) f.get("documentProperties", null); listenerList = new EventListenerList(); + data = (Content) f.get("data", null); + context = (AttributeContext) f.get("context", null); + documentFilter = (DocumentFilter) f.get("documentFilter", null); // Restore bidi structure //REMIND(bcb) This creates an initial bidi element to account for diff --git a/jdk/src/share/classes/javax/swing/text/DefaultCaret.java b/jdk/src/share/classes/javax/swing/text/DefaultCaret.java index 5eb0b2b10fe..cd17fed60bd 100644 --- a/jdk/src/share/classes/javax/swing/text/DefaultCaret.java +++ b/jdk/src/share/classes/javax/swing/text/DefaultCaret.java @@ -1516,7 +1516,30 @@ public class DefaultCaret extends Rectangle implements Caret, FocusListener, Mou private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { - s.defaultReadObject(); + ObjectInputStream.GetField f = s.readFields(); + + EventListenerList newListenerList = (EventListenerList) f.get("listenerList", null); + if (newListenerList == null) { + throw new InvalidObjectException("Null listenerList"); + } + listenerList = newListenerList; + component = (JTextComponent) f.get("component", null); + updatePolicy = f.get("updatePolicy", 0); + visible = f.get("visible", false); + active = f.get("active", false); + dot = f.get("dot", 0); + mark = f.get("mark", 0); + selectionTag = f.get("selectionTag", null); + selectionVisible = f.get("selectionVisible", false); + flasher = (Timer) f.get("flasher", null); + magicCaretPosition = (Point) f.get("magicCaretPosition", null); + dotLTR = f.get("dotLTR", false); + markLTR = f.get("markLTR", false); + ownsSelection = f.get("ownsSelection", false); + forceCaretPositionChange = f.get("forceCaretPositionChange", false); + caretWidth = f.get("caretWidth", 0); + aspectRatio = f.get("aspectRatio", 0.0f); + handler = new Handler(); if (!s.readBoolean()) { dotBias = Position.Bias.Forward; diff --git a/jdk/src/share/classes/javax/swing/text/DefaultStyledDocument.java b/jdk/src/share/classes/javax/swing/text/DefaultStyledDocument.java index 78788cbfad1..09faa5671cb 100644 --- a/jdk/src/share/classes/javax/swing/text/DefaultStyledDocument.java +++ b/jdk/src/share/classes/javax/swing/text/DefaultStyledDocument.java @@ -1082,8 +1082,9 @@ public class DefaultStyledDocument extends AbstractDocument implements StyledDoc private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { - listeningStyles = new Vector