Skip to main content

NotSerializableException

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.

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

Popular posts from this blog

NullPointerException

java.lang.NullPointerException NullPointerException is described in the javadoc comments as: Thrown when an application attempts to use null in a case where an object is required. These include: Calling the instance method of a null object. Accessing or modifying the field of a null object. Taking the length of null as if it were an array. Accessing or modifying the slots of null as if it were an array. Throwing null as if it were a Throwable value. Applications should throw instances of this class to indicate other illegal uses of the null object. author: unascribed version: 1.19, 12/19/03 since: JDK1.0 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.lang.NullPointerException: ' is thrown within the method: com.sun.corba.se.impl.interceptors.ClientRequestInfoImpl.get_r

Connection refused: No available router to destination

This is a simple symptom-cause-solution blog entry only. I hope these blogs will help fellow administrators. Symptom The following exception occurs in WebLogic server logs. Most likely to occur during WebLogic server start-up, but similar exceptions may occur at other times. java.net.ConnectException: t3://myserver:8000: Destination unreachable; nested exception is: java.net.ConnectException: Connection refused: connect; No available router to destination] at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:49) at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:773) at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:363) at weblogic.jndi.Environment.getContext(Environment.java:307) at weblogic.jndi.Environment.getContext(Environment.java:277) Cause This message (Connection refused: connect; No available

Recovering WebLogic Passwords

In one of my previous articles ( here ) I explained that the SerializedSystemIni.dat file in WebLogic contains the key used to encrypt and decrypt passwords. If you're not currently keeping this file secure I suggest you do, as with it someone can (to name a few things): Decrypt the WebLogic admin username and password from boot.properties. Recover database passwords, if JDBC Connection pools are configured, from config.xml. Recover the keystore passwords from config.xml and obtain SSL certificates stored in the jks keystores. Essentially, they can do whatever they want, so if you don't know who can read your SerializedSystemIni.dat files, look... now. In this article I will show how easy it is for this file to be used to recover lost passwords via a simple WLST script. The Script The script I use to decrypt passwords is incredibly short, and it works with WebLogic 8, 9 and 10 (probably for version 7 too). To use it, just create a new file called decryptpwd.py and paste the fol