Index: tree-edit/src/org/netbeans/modules/xml/tree/editor/TreeEditorComponent.java
===================================================================
RCS file: /cvs/xml/tree-edit/src/org/netbeans/modules/xml/tree/editor/TreeEditorComponent.java,v
retrieving revision 1.2.4.4
diff -u -r1.2.4.4 TreeEditorComponent.java
--- tree-edit/src/org/netbeans/modules/xml/tree/editor/TreeEditorComponent.java 30 Jan 2002 15:45:11 -0000 1.2.4.4
+++ tree-edit/src/org/netbeans/modules/xml/tree/editor/TreeEditorComponent.java 12 Jun 2002 19:19:11 -0000
@@ -197,6 +197,11 @@
* @return true
if close succeeded
*/
protected boolean closeLast () {
+ //#19687 it should be invariant!
+ if ( support == null ) {
+ return true;
+ }
+
if (!!! support.canClose()) {
// if we cannot close the last window
return false;
@@ -240,6 +245,11 @@
protected void componentActivated () {
super.componentActivated();
+ //#19687 it should be invariant!
+ if ( explorerPanel == null ) {
+ return;
+ }
+
try {
Method explorerPanelComponentActivatedMethod = ExplorerPanel.class.getDeclaredMethod ("componentActivated", null); // NOI18N
explorerPanelComponentActivatedMethod.setAccessible (true);
@@ -258,6 +268,11 @@
protected void componentDeactivated () {
super.componentDeactivated();
+ //#19687 it should be invariant!
+ if ( explorerPanel == null ) {
+ return;
+ }
+
try {
Method explorerPanelComponentDeactivatedMethod = ExplorerPanel.class.getDeclaredMethod ("componentDeactivated", null); // NOI18N
explorerPanelComponentDeactivatedMethod.setAccessible (true);
@@ -272,6 +287,25 @@
}
+ /**
+ * Test top component validity. For invalid ones return null
.
+ */
+ protected Object writeReplace() throws ObjectStreamException {
+
+ //#19687 it should be invariant!
+ if (support == null) {
+ return null;
+ }
+
+ // #24350 do not write down data for invalid data objects
+ DataObject dataObject = support.getDataObject();
+ if (dataObject.isValid() == false) {
+ return null;
+ }
+
+ return super.writeReplace();
+ }
+
/** Serialize this top component.
* Subclasses wishing to store state must call the super method, then write to the stream.
* @param out the stream to serialize to
@@ -280,11 +314,6 @@
if ( DEBUG ) Util.debug("TreeEditorComponent.writeExternal()"); // NOI18N
super.writeExternal (out);
-
- if (support == null) { //!!! it should be invariant!
- return; //#19687
- }
-
out.writeObject (support.getEnv());
if ( DEBUG ) Util.debug("\tdone."); // NOI18N
@@ -299,8 +328,18 @@
super.readExternal (in);
- TreeEditorSupport.Env env = (TreeEditorSupport.Env) in.readObject();
- support = (TreeEditorSupport) env.findTreeEditorSupport();
+ try {
+ TreeEditorSupport.Env env = (TreeEditorSupport.Env) in.readObject();
+ support = (TreeEditorSupport) env.findTreeEditorSupport();
+ } catch (OptionalDataException exc) { //!!! is should be invariant (see writeExternal)
+ if ( exc.eof == true ) { // caused because 'out.writeObject (support.getEnv());' was not called
+ return; // #20487
+ } else {
+ throw exc;
+ }
+ } catch (ClassCastException exc) { // env.findTreeEditorSupport(); // #20145
+ return;
+ }
if (!!! ((DataObject)getXMLDataObjectLook()).isValid() ) {
return;