-
Bug
-
Resolution: Fixed
-
P4
-
1.3.0
-
ladybird
-
generic, x86
-
generic, windows_98, windows_nt
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2031639 | 1.4.0 | Hania Gajewska | P4 | Resolved | Fixed | beta |
Name: skT88420 Date: 02/01/2000
java version "1.3.0rc1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)
Serializing JInternalFrames failes with incorrect exception.
Here is the source of the reduced testcase (zip file available on request):
import java.io.Serializable;
import java.util.*;
public abstract class D1 implements Serializable, Cloneable {
protected D1( ){
};
}
import java.io.*;
import java.util.*;
import java.math.*;
public abstract class D2 extends D1 {
protected D2( ){
super( );
}
}
import java.math.*;
import java.util.*;
import java.sql.*;
public class D3 extends D2 {
public D3() {
}
}
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
public class Fr extends JInternalFrame implements Serializable{
private int serialNo;
public Fr( ){
super( );
}
public Fr( String title, boolean resizable, boolean closable,
boolean maximizable, boolean iconifiable ){
super( title, resizable, closable, maximizable, iconifiable );
}
public int getSerialNo( ){ return this.serialNo; }
public void setSerialNo( int n ){ this.serialNo = n; }
}
import java.beans.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.Container;
import java.awt.Dimension;
import java.rmi.RemoteException;
import java.awt.event.*;
public class Mg extends DefaultDesktopManager{
private int posX = 50;
private int posY = 50;
private int width = 100;
private int height = 100;
private int frameSerialNo;
public Mg( ){
super( );
this.frameSerialNo = 0;
}
public void showFrame( Fr frame, JDesktopPane desk ) {
frame.setBounds( posX, posY, width, height );
desk.add( frame, JLayeredPane.DEFAULT_LAYER );
if (frame.isIcon( )) {
try {
frame.setIcon( false );
} catch (PropertyVetoException pve) {
}
} else {
frame.show( );
}
}
public void showPanel( P1 panel, JDesktopPane desk ) {
Fr frame = new Fr( "test", true, true, true, true );
frame.setSerialNo( ++this.frameSerialNo );
frame.setContentPane( panel );
showFrame( frame, desk );
}
}
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.metal.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class Mn extends JApplet {
private static final String DESKTOP_DIRECTORY = "desktops";
private Mg manager;
private JDesktopPane desk;
private P1 panel;
private D1 doc;
private JButton create, save, restore, quit;
private JPanel bGrid;
public Mn( ){
super( );
}
public void init( ){
try {
UIManager.setLookAndFeel( new MetalLookAndFeel( ) );
} catch (UnsupportedLookAndFeelException ulafe) {
}
this.create = new JButton( "Create" );
this.create.addActionListener( new ActionListener( ){
public void actionPerformed( ActionEvent ae ){
System.out.println( "Creating" );
Mn.this.doc = new D3( );
Mn.this.panel = new P3( );
Mn.this.panel.setModel( doc );
Mn.this.manager.showPanel(
Mn.this.panel, Mn.this.desk );
}
});
this.save = new JButton( "Save" );
this.save.addActionListener( new ActionListener( ){
public void actionPerformed( ActionEvent ae ){
System.out.println( "Saving" );
saveDesktop( );
}
});
this.restore = new JButton( "Restore" );
this.restore.addActionListener( new ActionListener( ){
public void actionPerformed( ActionEvent ae ){
System.out.println( "Restoring" );
restoreDesktop( );
}
});
this.quit = new JButton( "Quit" );
this.quit.addActionListener( new ActionListener( ){
public void actionPerformed( ActionEvent ae ){
System.out.println( "Quitting" );
stop( );
destroy( );
System.exit( 0 );
}
});
this.bGrid = new JPanel( new GridLayout( 1, 4 ) );
this.bGrid.add( create, 0 );
this.bGrid.add( save, 1 );
this.bGrid.add( restore, 2 );
this.bGrid.add( quit, 3 );
this.manager = new Mg( );
this.desk = new JDesktopPane( );
this.desk.setDesktopManager( this.manager );
this.desk.setOpaque( false );
getContentPane( ).add( this.bGrid, BorderLayout.NORTH );
getContentPane( ).add( this.desk, BorderLayout.CENTER );
}
public void start( ){
}
public void stop( ){
}
public void destroy( ){ }
private void saveDesktop( ){
JInternalFrame f[] = this.desk.getAllFrames( );
try {
saveClientState( f );
} catch( Exception e ){
System.out.println( "saveDesktop " + e );
}
}
private void restoreDesktop( ){
int x, y;
try {
JInternalFrame f[] = restoreClientState( );
if (f==null) return; // Nothing to restore
x = y = 100;
for (int i=0; i<f.length; i++) {
if (f[ i ] instanceof Fr) {
this.manager.showFrame( (Fr) f[ i ],
this.desk );
}
}
} catch (Exception e) {
System.out.println( e );
}
}
public static final void main( String argv[] ){
int width = 500, height = 500;
Frame appletFrame = new Frame("testcase");
Mn theApplet = new Mn( );
appletFrame.pack( );
appletFrame.add( theApplet, "Center" );
theApplet.init( );
appletFrame.pack( );
appletFrame.setBounds( 40, 40, width, height );
appletFrame.show( );
theApplet.start( );
}
public final void saveClientState( JInternalFrame state[] )
throws IOException{
FileOutputStream f = new FileOutputStream(
DESKTOP_DIRECTORY + File.separator + "u" );
ObjectOutputStream o = new ObjectOutputStream( f );
o.writeObject( state );
o.close( );
}
public final JInternalFrame[] restoreClientState( )throws IOException {
JInternalFrame result[];
try {
FileInputStream f = new FileInputStream(
DESKTOP_DIRECTORY + File.separator +
"u" );
ObjectInputStream o = new ObjectInputStream( f );
result = (JInternalFrame[]) o.readObject( );
o.close( );
} catch (Exception e) {
System.out.println( e );
result = null;
}
return result;
}
}
NOTE : Remaining portion pasted in the comments section of this report.
(Review ID: 100602)
======================================================================
- backported by
-
JDK-2031639 Serializing JInternalFrame throws Exception
-
- Resolved
-
- duplicates
-
JDK-4333421 JInternalFrame not Serializable
-
- Closed
-