java.io.NotSerializableException
NotSerializableException is described in the javadoc comments as:
Thrown when an instance is required to have a Serializable interface. The serialization runtime or the class of the instance can throw this exception. The argument should be the name of the class.
author: unascribed version: 1.14, 12/19/03 since: JDK1.1
Where is this exception thrown?
Following, is a list of exception messages cross-referenced to the source code responsible for throwing them. Click on the method link to view the code and see how the exception is thrown.
- The message 'java.io.NotSerializableException: ...' is thrown within the method:
com.sun.corba.se.impl.io.IIOPOutputStream.outputObject(Object) - The message 'java.io.NotSerializableException: ...' is thrown within the method:
com.sun.org.apache.xerces.internal.dom.PSVIAttrNSImpl.readObject(ObjectInputStream) - The message 'java.io.NotSerializableException: ...' is thrown within the method:
com.sun.org.apache.xerces.internal.dom.PSVIAttrNSImpl.writeObject(ObjectOutputStream) - The message 'java.io.NotSerializableException: ...' is thrown within the method:
com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl.readObject(ObjectInputStream) - The message 'java.io.NotSerializableException: ...' is thrown within the method:
com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl.writeObject(ObjectOutputStream) - The message 'java.io.NotSerializableException: ...' is thrown within the method:
com.sun.org.apache.xerces.internal.dom.PSVIElementNSImpl.readObject(ObjectInputStream) - The message 'java.io.NotSerializableException: ...' is thrown within the method:
com.sun.org.apache.xerces.internal.dom.PSVIElementNSImpl.writeObject(ObjectOutputStream) - The message 'java.io.NotSerializableException: ...' is thrown within the method:
java.io.ObjectOutputStream.writeObject0(Object, boolean) - The message 'java.io.NotSerializableException: ...' is thrown within the method:
javax.swing.plaf.synth.SynthLookAndFeel.writeObject(java.io.ObjectOutputStream) - The message 'java.io.NotSerializableException: ... is not serializable as a key in an AttributeSet' is thrown within the method:
javax.swing.text.StyleContext.writeAttributeSet(ObjectOutputStream, AttributeSet) - The message 'java.io.NotSerializableException: ... is not serializable as a value in an AttributeSet' is thrown within the method:
javax.swing.text.StyleContext.writeAttributeSet(ObjectOutputStream, AttributeSet) - The message 'java.io.NotSerializableException: Not serializable.' is thrown within the method:
java.util.prefs.NodeChangeEvent.readObject(java.io.ObjectInputStream) - The message 'java.io.NotSerializableException: Not serializable.' is thrown within the method:
java.util.prefs.NodeChangeEvent.writeObject(java.io.ObjectOutputStream) - The message 'java.io.NotSerializableException: Not serializable.' is thrown within the method:
java.util.prefs.PreferenceChangeEvent.readObject(java.io.ObjectInputStream) - The message 'java.io.NotSerializableException: Not serializable.' is thrown within the method:
java.util.prefs.PreferenceChangeEvent.writeObject(java.io.ObjectOutputStream) - The message 'java.io.NotSerializableException: unrecognized type/format combination: ... / ...' is thrown within the method:
java.security.KeyRep.readResolve()
How is this exception thrown?
The following sub-sections identify where this exception is thrown, and how (or why) the code is throwing the exception.
Any source code quoted in this section is subject to the Java Research License unless stated otherwise.
com.sun.corba.se.impl.io.IIOPOutputStream.outputObject(Object)
private void outputObject(final Object obj) throws IOException { currentObject = obj; Class currclass = obj.getClass(); currentClassDesc = ObjectStreamClass.lookup(currclass); if (currentClassDesc == null) { throw new NotSerializableException(currclass.getName()); } if (currentClassDesc.isExternalizable()) { orbStream.write_octet(streamFormatVersion); Externalizable ext = (Externalizable) obj; ext.writeExternal(this); } else { int stackMark = classDescStack.size(); try { ObjectStreamClass next; while ((next = currentClassDesc.getSuperclass()) != null) { classDescStack.push(currentClassDesc); currentClassDesc = next; } do { WriteObjectState oldState = writeObjectState; try { setState(NOT_IN_WRITE_OBJECT); if (currentClassDesc.hasWriteObject()) { invokeObjectWriter(currentClassDesc, obj); } else { defaultWriteObjectDelegate(); } } finally { setState(oldState); } } while (classDescStack.size() > stackMark && (currentClassDesc = (ObjectStreamClass) classDescStack.pop()) != null); } finally { classDescStack.setSize(stackMark); } } }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
com.sun.org.apache.xerces.internal.dom.PSVIAttrNSImpl.readObject(ObjectInputStream)
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { throw new NotSerializableException(getClass().getName()); }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
com.sun.org.apache.xerces.internal.dom.PSVIAttrNSImpl.writeObject(ObjectOutputStream)
private void writeObject(ObjectOutputStream out) throws IOException { throw new NotSerializableException(getClass().getName()); }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl.readObject(ObjectInputStream)
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { throw new NotSerializableException(getClass().getName()); }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl.writeObject(ObjectOutputStream)
private void writeObject(ObjectOutputStream out) throws IOException { throw new NotSerializableException(getClass().getName()); }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
com.sun.org.apache.xerces.internal.dom.PSVIElementNSImpl.readObject(ObjectInputStream)
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { throw new NotSerializableException(getClass().getName()); }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
com.sun.org.apache.xerces.internal.dom.PSVIElementNSImpl.writeObject(ObjectOutputStream)
private void writeObject(ObjectOutputStream out) throws IOException { throw new NotSerializableException(getClass().getName()); }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
java.io.ObjectOutputStream.writeObject0(Object, boolean)
/** * Underlying writeObject/writeUnshared implementation. */ private void writeObject0(Object obj, boolean unshared) throws IOException { boolean oldMode = bout.setBlockDataMode(false); depth++; try { int h; if ((obj = subs.lookup(obj)) == null) { writeNull(); return; } else if (!unshared && (h = handles.lookup(obj)) != -1) { writeHandle(h); return; } else if (obj instanceof Class) { writeClass((Class) obj, unshared); return; } else if (obj instanceof ObjectStreamClass) { writeClassDesc((ObjectStreamClass) obj, unshared); return; } Object orig = obj; Class cl = obj.getClass(); ObjectStreamClass desc; for (; ; ) { Class repCl; desc = ObjectStreamClass.lookup(cl, true); if (!desc.hasWriteReplaceMethod() || (obj = desc.invokeWriteReplace(obj)) == null || (repCl = obj.getClass()) == cl) { break; } cl = repCl; } if (enableReplace) { Object rep = replaceObject(obj); if (rep != obj && rep != null) { cl = rep.getClass(); desc = ObjectStreamClass.lookup(cl, true); } obj = rep; } if (obj != orig) { subs.assign(orig, obj); if (obj == null) { writeNull(); return; } else if (!unshared && (h = handles.lookup(obj)) != -1) { writeHandle(h); return; } else if (obj instanceof Class) { writeClass((Class) obj, unshared); return; } else if (obj instanceof ObjectStreamClass) { writeClassDesc((ObjectStreamClass) obj, unshared); return; } } if (obj instanceof String) { writeString((String) obj, unshared); } else if (cl.isArray()) { writeArray(obj, desc, unshared); } else if (obj instanceof Enum) { writeEnum((Enum) obj, desc, unshared); } else if (obj instanceof Serializable) { writeOrdinaryObject(obj, desc, unshared); } else { throw new NotSerializableException(cl.getName()); } } finally { depth--; bout.setBlockDataMode(oldMode); } }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
javax.swing.plaf.synth.SynthLookAndFeel.writeObject(java.io.ObjectOutputStream)
private void writeObject(java.io.ObjectOutputStream out) throws IOException { throw new NotSerializableException(this.getClass().getName()); }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
javax.swing.text.StyleContext.writeAttributeSet(ObjectOutputStream, AttributeSet)
/** * Writes a set of attributes to the given object stream * for the purpose of serialization. This will take * special care to deal with static attribute keys that * have been registered wit the * <code>registerStaticAttributeKey</code> method. * Any attribute key not regsitered as a static key * will be serialized directly. All values are expected * to be serializable. * @param out the output stream * @param a the attribute set * @exception IOException on any I/O error */ public static void writeAttributeSet(ObjectOutputStream out, AttributeSet a) throws IOException { int n = a.getAttributeCount(); out.writeInt(n); Enumeration keys = a.getAttributeNames(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); if (key instanceof Serializable) { out.writeObject(key); } else { Object ioFmt = freezeKeyMap.get(key); if (ioFmt == null) { throw new NotSerializableException(key.getClass().getName() + ' is not serializable as a key in an AttributeSet'); } out.writeObject(ioFmt); } Object value = a.getAttribute(key); Object ioFmt = freezeKeyMap.get(value); if (value instanceof Serializable) { out.writeObject((ioFmt != null) ? ioFmt : value); } else { if (ioFmt == null) { throw new NotSerializableException(value.getClass().getName() + ' is not serializable as a value in an AttributeSet'); } out.writeObject(ioFmt); } } }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
java.util.prefs.NodeChangeEvent.readObject(java.io.ObjectInputStream)
/** * Throws NotSerializableException, since NodeChangeEvent objects are not * intended to be serializable. */ private void readObject(java.io.ObjectInputStream in) throws NotSerializableException { throw new NotSerializableException('Not serializable.'); }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
java.util.prefs.NodeChangeEvent.writeObject(java.io.ObjectOutputStream)
/** * Throws NotSerializableException, since NodeChangeEvent objects are not * intended to be serializable. */ private void writeObject(java.io.ObjectOutputStream out) throws NotSerializableException { throw new NotSerializableException('Not serializable.'); }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
java.util.prefs.PreferenceChangeEvent.readObject(java.io.ObjectInputStream)
/** * Throws NotSerializableException, since PreferenceChangeEvent objects * are not intended to be serializable. */ private void readObject(java.io.ObjectInputStream in) throws NotSerializableException { throw new NotSerializableException('Not serializable.'); }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
java.util.prefs.PreferenceChangeEvent.writeObject(java.io.ObjectOutputStream)
/** * Throws NotSerializableException, since NodeChangeEvent objects * are not intended to be serializable. */ private void writeObject(java.io.ObjectOutputStream out) throws NotSerializableException { throw new NotSerializableException('Not serializable.'); }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
java.security.KeyRep.readResolve()
/** * Resolve the Key object. * This method supports three Type/format combinations: * <ul> * <li> Type.SECRET/'RAW' - returns a SecretKeySpec object * constructed using encoded key bytes and algorithm * <li> Type.PUBLIC/'X.509' - gets a KeyFactory instance for * the key algorithm, constructs an X509EncodedKeySpec with the * encoded key bytes, and generates a public key from the spec * <li> Type.PRIVATE/'PKCS#8' - gets a KeyFactory instance for * the key algorithm, constructs a PKCS8EncodedKeySpec with the * encoded key bytes, and generates a private key from the spec * </ul> * * @return the resolved Key object * @exception NotSerializableException if the Type/format * combination is unrecognized, if the algorithm, key format, or * encoded key bytes are unrecognized/invalid, of if the * resolution of the key fails for any reason */ protected Object readResolve() throws ObjectStreamException { try { if (type == Type.SECRET && RAW.equals(format)) { return new SecretKeySpec(encoded, algorithm); } else if (type == Type.PUBLIC && X509.equals(format)) { KeyFactory f = KeyFactory.getInstance(algorithm); return f.generatePublic(new X509EncodedKeySpec(encoded)); } else if (type == Type.PRIVATE && PKCS8.equals(format)) { KeyFactory f = KeyFactory.getInstance(algorithm); return f.generatePrivate(new PKCS8EncodedKeySpec(encoded)); } else { throw new NotSerializableException('unrecognized type/format combination: ' + type + '/' + format); } } catch (NotSerializableException nse) { throw nse; } catch (Exception e) { NotSerializableException nse = new NotSerializableException('java.security.Key: ' + '[' + type + '] ' + '[' + algorithm + '] ' + '[' + format + ']'); nse.initCause(e); throw nse; } }
Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html
Comments
Post a Comment