Skip to main content

ClassNotFoundException

java.lang.ClassNotFoundException

ClassNotFoundException is described in the javadoc comments as:

Thrown when an application tries to load in a class through its string name using:
  • The forName method in class Class.
  • The findSystemClass method in class ClassLoader .
  • The loadClass method in class ClassLoader.

but no definition for the class with the specified name could be found.

As of release 1.4, this exception has been retrofitted to conform to the general purpose exception-chaining mechanism. The 'optional exception that was raised while loading the class' that may be provided at construction time and accessed via the {link: #getException()} method is now known as the cause, and may be accessed via the {@link Throwable#getCause()} method, as well as the aforementioned 'legacy method.'
author: unascribed version: 1.20, 02/19/04 see: java.lang.Class#forName(java.lang.String) see: java.lang.ClassLoader#findSystemClass(java.lang.String) see: java.lang.ClassLoader#loadClass(java.lang.String, boolean) 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.

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.util.JDKClassLoader.loadClass(Class, String)

static Class loadClass(Class aClass, String className) throws ClassNotFoundException {
    if (className == null) {
        throw new NullPointerException();
    }
    if (className.length() == 0) {
        throw new ClassNotFoundException();
    }
    ClassLoader loader;
    if (aClass != null) {
        loader = aClass.getClassLoader();
    } else {
        loader = bridge.getLatestUserDefinedLoader();
    }
    Object key = classCache.createKey(className, loader);
    if (classCache.knownToFail(key)) {
        throw new ClassNotFoundException(className);
    } else {
        try {
            return Class.forName(className, false, loader);
        } catch (ClassNotFoundException cnfe) {
            classCache.recordFailure(key);
            throw cnfe;
        }
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.corba.se.impl.util.Utility.loadStubClass(String, String, Class)

public static Class loadStubClass(String repID, String remoteCodebase, Class expectedType) throws ClassNotFoundException {
    if (repID.length() == 0) {
        throw new ClassNotFoundException();
    }
    String className = Utility.stubNameFromRepID(repID);
    ClassLoader expectedTypeClassLoader = (expectedType == null ? null : expectedType.getClassLoader());
    try {
        return loadClassOfType(className, remoteCodebase, expectedTypeClassLoader, expectedType, expectedTypeClassLoader);
    } catch (ClassNotFoundException e) {
        return loadClassOfType(PackagePrefixChecker.packagePrefix() + className, remoteCodebase, expectedTypeClassLoader, expectedType, expectedTypeClassLoader);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.corba.se.impl.io.IIOPInputStream.inputObject(Class, String, com.sun.org.omg.SendingContext.CodeBase, int)

private Object inputObject(Class clz, String repositoryID, com.sun.org.omg.SendingContext.CodeBase sender, int offset) throws IOException, ClassNotFoundException {
    currentClassDesc = ObjectStreamClass.lookup(clz);
    currentClass = currentClassDesc.forClass();
    if (currentClass == null) throw new ClassNotFoundException(currentClassDesc.getName());
    try {
        if (currentClassDesc.isExternalizable()) {
            try {
                currentObject = (currentClass == null) ? null : currentClassDesc.newInstance();
                if (currentObject != null) {
                    activeRecursionMgr.addObject(offset, currentObject);
                    readFormatVersion();
                    Externalizable ext = (Externalizable) currentObject;
                    ext.readExternal(this);
                }
            } catch (InvocationTargetException e) {
                InvalidClassException exc = new InvalidClassException(currentClass.getName(), 'InvocationTargetException accessing no-arg constructor');
                exc.initCause(e);
                throw exc;
            } catch (UnsupportedOperationException e) {
                InvalidClassException exc = new InvalidClassException(currentClass.getName(), 'UnsupportedOperationException accessing no-arg constructor');
                exc.initCause(e);
                throw exc;
            } catch (InstantiationException e) {
                InvalidClassException exc = new InvalidClassException(currentClass.getName(), 'InstantiationException accessing no-arg constructor');
                exc.initCause(e);
                throw exc;
            }
        } else {
            ObjectStreamClass currdesc = currentClassDesc;
            Class currclass = currentClass;
            int spBase = spClass;
            for (currdesc = currentClassDesc, currclass = currentClass; currdesc != null && currdesc.isSerializable(); currdesc = currdesc.getSuperclass()) {
                Class cc = currdesc.forClass();
                Class cl;
                for (cl = currclass; cl != null; cl = cl.getSuperclass()) {
                    if (cc == cl) {
                        break;
                    } else {
                    }
                }
                spClass++;
                if (spClass >= classes.length) {
                    int newlen = classes.length * 2;
                    Class[] newclasses = new Class[newlen];
                    ObjectStreamClass[] newclassdesc = new ObjectStreamClass[newlen];
                    System.arraycopy(classes, 0, newclasses, 0, classes.length);
                    System.arraycopy(classdesc, 0, newclassdesc, 0, classes.length);
                    classes = newclasses;
                    classdesc = newclassdesc;
                }
                if (cl == null) {
                    classdesc[spClass] = currdesc;
                    classes[spClass] = null;
                } else {
                    classdesc[spClass] = currdesc;
                    classes[spClass] = cl;
                    currclass = cl.getSuperclass();
                }
            }
            try {
                currentObject = (currentClass == null) ? null : currentClassDesc.newInstance();
                activeRecursionMgr.addObject(offset, currentObject);
            } catch (InvocationTargetException e) {
                InvalidClassException exc = new InvalidClassException(currentClass.getName(), 'InvocationTargetException accessing no-arg constructor');
                exc.initCause(e);
                throw exc;
            } catch (UnsupportedOperationException e) {
                InvalidClassException exc = new InvalidClassException(currentClass.getName(), 'UnsupportedOperationException accessing no-arg constructor');
                exc.initCause(e);
                throw exc;
            } catch (InstantiationException e) {
                InvalidClassException exc = new InvalidClassException(currentClass.getName(), 'InstantiationException accessing no-arg constructor');
                exc.initCause(e);
                throw exc;
            }
            try {
                for (spClass = spClass; spClass > spBase; spClass--) {
                    currentClassDesc = classdesc[spClass];
                    currentClass = classes[spClass];
                    if (classes[spClass] != null) {
                        ReadObjectState oldState = readObjectState;
                        setState(DEFAULT_STATE);
                        try {
                            if (currentClassDesc.hasWriteObject()) {
                                readFormatVersion();
                                boolean calledDefaultWriteObject = readBoolean();
                                readObjectState.beginUnmarshalCustomValue(this, calledDefaultWriteObject, (currentClassDesc.readObjectMethod != null));
                            } else {
                                if (currentClassDesc.hasReadObject()) setState(IN_READ_OBJECT_REMOTE_NOT_CUSTOM_MARSHALED);
                            }
                            if (!invokeObjectReader(currentClassDesc, currentObject, currentClass) || readObjectState == IN_READ_OBJECT_DEFAULTS_SENT) {
                                ObjectStreamField[] fields = currentClassDesc.getFieldsNoCopy();
                                if (fields.length > 0) {
                                    inputClassFields(currentObject, currentClass, fields, sender);
                                }
                            }
                            if (currentClassDesc.hasWriteObject()) readObjectState.endUnmarshalCustomValue(this);
                        } finally {
                            setState(oldState);
                        }
                    } else {
                        ObjectStreamField[] fields = currentClassDesc.getFieldsNoCopy();
                        if (fields.length > 0) {
                            inputClassFields(null, currentClass, fields, sender);
                        }
                    }
                }
            } finally {
                spClass = spBase;
            }
        }
    } finally {
        activeRecursionMgr.removeObject(offset);
    }
    return currentObject;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.corba.se.impl.util.JDKBridge.loadClassM(String, String, boolean)

private static Class loadClassM(String className, String remoteCodebase, boolean useCodebaseOnly) throws ClassNotFoundException {
    try {
        return JDKClassLoader.loadClass(null, className);
    } catch (ClassNotFoundException e) {
    }
    try {
        if (!useCodebaseOnly && remoteCodebase != null) {
            return RMIClassLoader.loadClass(remoteCodebase, className);
        } else {
            return RMIClassLoader.loadClass(className);
        }
    } catch (MalformedURLException e) {
        className = className + ': ' + e.toString();
    }
    throw new ClassNotFoundException(className);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.jmx.mbeanserver.ClassLoaderRepositorySupport.loadClass(LoaderEntry, String, ClassLoader, ClassLoader)

private Class loadClass(final LoaderEntry list[], final String className, final ClassLoader without, final ClassLoader stop) throws ClassNotFoundException {
    final int size = list.length;
    for (int i = 0; i < size; i++) {
        try {
            final ClassLoader cl = list[i].loader;
            if (cl == null) return Class.forName(className, false, null);
            if (cl == without) continue;
            if (cl == stop) break;
            if (isTraceOn()) {
                trace('loadClass', 'trying loader = ' + cl);
            }
            return Class.forName(className, false, cl);
        } catch (ClassNotFoundException e) {
        }
    }
    throw new ClassNotFoundException(className);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.jmx.mbeanserver.ClassLoaderRepositorySupport.startValidSearch(ClassLoader, String)

private synchronized void startValidSearch(ClassLoader aloader, String className) throws ClassNotFoundException {
    Vector excluded = (Vector) search.get(className);
    if ((excluded != null) && (excluded.contains(aloader))) {
        if (isTraceOn()) {
            trace('startValidSearch', 'already requested loader=' + aloader + ' class= ' + className);
        }
        throw new ClassNotFoundException(className);
    }
    if (excluded == null) {
        excluded = new Vector(1);
        search.put(className, excluded);
    }
    excluded.addElement(aloader);
    if (isTraceOn()) {
        trace('startValidSearch', 'loader=' + aloader + ' class= ' + className);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.jmx.mbeanserver.JmxMBeanServer.deserialize(String, byte[])

/**
     * De-serializes a byte array in the context of a given MBean class loader.
     * The class loader is the one that loaded the class with name 'className'.
     * @param className The name of the class whose class loader should be 
     *      used for the de-serialization.
     * @param data The byte array to be de-sererialized.
     * @return  The de-serialized object stream.
     * @exception OperationsException Any of the usual Input/Output 
     *      related exceptions.
     * @exception ReflectionException The specified class could not be 
     *      loaded by the default loader repository     
     */
public ObjectInputStream deserialize(String className, byte[] data) throws OperationsException, ReflectionException {
    if (className == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), 'Null className passed in parameter');
    }
    final ClassLoaderRepository clr = getClassLoaderRepository();
    Class theClass;
    try {
        if (clr == null) throw new ClassNotFoundException(className);
        theClass = clr.loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e, 'The given class could not be ' + 'loaded by the default loader ' + 'repository');
    }
    return instantiator.deserialize(theClass.getClassLoader(), data);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.jmx.mbeanserver.MBeanInstantiatorImpl.deserialize(String, ObjectName, byte[], ClassLoader)

public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] data, ClassLoader loader) throws InstanceNotFoundException, OperationsException, ReflectionException {
    if (data == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), 'Null data passed in parameter');
    }
    if (data.length == 0) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), 'Empty data passed in parameter');
    }
    if (className == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), 'Null className passed in parameter');
    }
    Class theClass = null;
    if (loaderName == null) {
        theClass = findClass(className, loader);
    } else {
        try {
            ClassLoader instance = null;
            if (clr != null) instance = clr.getClassLoader(loaderName);
            if (instance == null) throw new ClassNotFoundException(className);
            theClass = Class.forName(className, false, instance);
        } catch (ClassNotFoundException e) {
            throw new ReflectionException(e, 'The MBean class could not be loaded by the ' + loaderName.toString() + ' class loader');
        }
    }
    ByteArrayInputStream bIn;
    ObjectInputStream objIn;
    String typeStr;
    bIn = new ByteArrayInputStream(data);
    try {
        objIn = new ObjectInputStreamWithLoader(bIn, theClass.getClassLoader());
    } catch (IOException e) {
        throw new OperationsException('An IOException occured trying to de-serialize the data');
    }
    return objIn;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.jmx.mbeanserver.MBeanInstantiatorImpl.findClassWithDefaultLoaderRepository(String)

public Class findClassWithDefaultLoaderRepository(String className) throws ReflectionException {
    Class theClass;
    if (className == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException('The class name cannot be null'), 'Exception occured during object instantiation');
    }
    try {
        if (clr == null) throw new ClassNotFoundException(className);
        theClass = clr.loadClass(className);
    } catch (ClassNotFoundException ee) {
        throw new ReflectionException(ee, 'The MBean class could not be loaded by the default loader repository');
    }
    return theClass;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.jmx.snmp.daemon.CommunicatorServer.loadClass(String)

/**
     * Load a class using the default loader repository
     **/
Class loadClass(String className) throws ClassNotFoundException {
    try {
        return Class.forName(className);
    } catch (ClassNotFoundException e) {
        final ClassLoaderRepository clr = MBeanServerFactory.getClassLoaderRepository(bottomMBS);
        if (clr == null) throw new ClassNotFoundException(className);
        return clr.loadClass(className);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.awt.datatransfer.DataFlavor.tryToLoadClass(String, ClassLoader)

/**
     * Tries to load a class from: the bootstrap loader, the system loader,
     * the context loader (if one is present) and finally the loader specified.
     * @param className the name of the class to be loaded
     * @param fallback the fallback loader
     * @return the class loaded
     * @exception ClassNotFoundException if class is not found
     */
protected static final Class<?> tryToLoadClass(String className, ClassLoader fallback) throws ClassNotFoundException {
    ClassLoader systemClassLoader = (ClassLoader) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

        public Object run() {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            return (cl != null) ? cl : ClassLoader.getSystemClassLoader();
        }
    });
    try {
        return Class.forName(className, true, systemClassLoader);
    } catch (ClassNotFoundException e2) {
        if (fallback != null) {
            return Class.forName(className, true, fallback);
        } else {
            throw new ClassNotFoundException(className);
        }
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.beans.Beans.resolveClass(ObjectStreamClass)

/**
     * Use the given ClassLoader rather than using the system class
     */
protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException {
    String cname = classDesc.getName();
    if (cname.startsWith('[')) {
        Class component;
        int dcount;
        for (dcount = 1; cname.charAt(dcount) == '['; dcount++) ;
        if (cname.charAt(dcount) == 'L') {
            component = loader.loadClass(cname.substring(dcount + 1, cname.length() - 1));
        } else {
            if (cname.length() != dcount + 1) {
                throw new ClassNotFoundException(cname);
            }
            component = primitiveType(cname.charAt(dcount));
        }
        int dim[] = new int[dcount];
        for (int i = 0; i < dcount; i++) {
            dim[i] = 0;
        }
        return Array.newInstance(component, dim).getClass();
    } else {
        return loader.loadClass(cname);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.io.ObjectInputStream.resolveProxyClass(String[])

/**
     * Returns a proxy class that implements the interfaces named in a proxy
     * class descriptor; subclasses may implement this method to read custom
     * data from the stream along with the descriptors for dynamic proxy
     * classes, allowing them to use an alternate loading mechanism for the
     * interfaces and the proxy class.
     * This method is called exactly once for each unique proxy class
     * descriptor in the stream.
     * The corresponding method in <code>ObjectOutputStream</code> is
     * <code>annotateProxyClass</code>.  For a given subclass of
     * <code>ObjectInputStream</code> that overrides this method, the
     * <code>annotateProxyClass</code> method in the corresponding subclass of
     * <code>ObjectOutputStream</code> must write any data or objects read by
     * this method.
     * The default implementation of this method in
     * <code>ObjectInputStream</code> returns the result of calling
     * <code>Proxy.getProxyClass</code> with the list of <code>Class</code>
     * objects for the interfaces that are named in the <code>interfaces</code>
     * parameter.  The <code>Class</code> object for each interface name
     * <code>i</code> is the value returned by calling
     *     Class.forName(i, false, loader)
     * where <code>loader</code> is that of the first non-<code>null</code>
     * class loader up the execution stack, or <code>null</code> if no
     * non-<code>null</code> class loaders are on the stack (the same class
     * loader choice used by the <code>resolveClass</code> method).  Unless any
     * of the resolved interfaces are non-public, this same value of
     * <code>loader</code> is also the class loader passed to
     * <code>Proxy.getProxyClass</code>; if non-public interfaces are present,
     * their class loader is passed instead (if more than one non-public
     * interface class loader is encountered, an
     * <code>IllegalAccessError</code> is thrown).  
     * If <code>Proxy.getProxyClass</code> throws an
     * <code>IllegalArgumentException</code>, <code>resolveProxyClass</code>
     * will throw a <code>ClassNotFoundException</code> containing the
     * <code>IllegalArgumentException</code>.
     * @param interfaces the list of interface names that were
     *  deserialized in the proxy class descriptor
     * @return  a proxy class for the specified interfaces
     * @throws IOException any exception thrown by the underlying
     *  <code>InputStream</code>
     * @throws ClassNotFoundException if the proxy class or any of the
     *   named interfaces could not be found
     * @see ObjectOutputStream#annotateProxyClass(Class)
     * @since 1.3
     */
protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException {
    ClassLoader latestLoader = latestUserDefinedLoader();
    ClassLoader nonPublicLoader = null;
    boolean hasNonPublicInterface = false;
    Class[] classObjs = new Class[interfaces.length];
    for (int i = 0; i < interfaces.length; i++) {
        Class cl = Class.forName(interfaces[i], false, latestLoader);
        if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
            if (hasNonPublicInterface) {
                if (nonPublicLoader != cl.getClassLoader()) {
                    throw new IllegalAccessError('conflicting non-public interface class loaders');
                }
            } else {
                nonPublicLoader = cl.getClassLoader();
                hasNonPublicInterface = true;
            }
        }
        classObjs[i] = cl;
    }
    try {
        return Proxy.getProxyClass(hasNonPublicInterface ? nonPublicLoader : latestLoader, classObjs);
    } catch (IllegalArgumentException e) {
        throw new ClassNotFoundException(null, e);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.lang.ClassLoader.findBootstrapClass0(String)

private Class findBootstrapClass0(String name) throws ClassNotFoundException {
    check();
    if (!checkName(name)) throw new ClassNotFoundException(name);
    return findBootstrapClass(name);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.lang.ClassLoader.findClass(String)

/**
     * Finds the class with the specified <a href='#name'>binary name</a>.
     * This method should be overridden by class loader implementations that
     * follow the delegation model for loading classes, and will be invoked by
     * the {@link #loadClass <tt>loadClass</tt>} method after checking the
     * parent class loader for the requested class.  The default implementation
     * throws a <tt>ClassNotFoundException</tt>.  
     * @param  name
     *         The <a href='#name'>binary name</a> of the class
     * @return  The resulting <tt>Class</tt> object
     * @throws  ClassNotFoundException
     *          If the class could not be found
     * @since  1.2
     */
protected Class<?> findClass(String name) throws ClassNotFoundException {
    throw new ClassNotFoundException(name);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.lang.ClassLoader.findSystemClass(String)

/**
     * Finds a class with the specified <a href='#name'>binary name</a>,
     * loading it if necessary.
     *  This method loads the class through the system class loader (see
     * {@link #getSystemClassLoader()}).  The <tt>Class</tt> object returned
     * might have more than one <tt>ClassLoader</tt> associated with it.
     * Subclasses of <tt>ClassLoader</tt> need not usually invoke this method,
     * because most class loaders need to override just {@link
     * #findClass(String)}.  
     * @param  name
     *         The <a href='#name'>binary name</a> of the class
     * @return  The <tt>Class</tt> object for the specified <tt>name</tt>
     * @throws  ClassNotFoundException
     *          If the class could not be found
     * @see  #ClassLoader(ClassLoader)
     * @see  #getParent()
     */
protected final Class<?> findSystemClass(String name) throws ClassNotFoundException {
    check();
    ClassLoader system = getSystemClassLoader();
    if (system == null) {
        if (!checkName(name)) throw new ClassNotFoundException(name);
        return findBootstrapClass(name);
    }
    return system.loadClass(name);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.URLClassLoader.findClass(String)

/**
     * Finds and loads the class with the specified name from the URL search
     * path. Any URLs referring to JAR files are loaded and opened as needed
     * until the class is found.
     * @param name the name of the class
     * @return the resulting class
     * @exception ClassNotFoundException if the class could not be found
     */
protected Class<?> findClass(final String name) throws ClassNotFoundException {
    try {
        return (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() {

            public Object run() throws ClassNotFoundException {
                String path = name.replace('.', '/').concat('.class');
                Resource res = ucp.getResource(path, false);
                if (res != null) {
                    try {
                        return defineClass(name, res);
                    } catch (IOException e) {
                        throw new ClassNotFoundException(name, e);
                    }
                } else {
                    throw new ClassNotFoundException(name);
                }
            }
        }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.rmi.server.RemoteObject.readObject(java.io.ObjectInputStream)

/**
     * <code>readObject</code> for custom serialization.
     * This method reads this object's serialized form for this class
     * as follows:
     * The <code>readUTF</code> method is invoked on <code>in</code>
     * to read the external ref type name for the <code>RemoteRef</code>
     * instance to be filled in to this object's <code>ref</code> field.
     * If the string returned by <code>readUTF</code> has length zero,
     * the <code>readObject</code> method is invoked on <code>in</code>,
     * and than the value returned by <code>readObject</code> is cast to
     * <code>RemoteRef</code> and this object's <code>ref</code> field is
     * set to that value.
     * Otherwise, this object's <code>ref</code> field is set to a
     * <code>RemoteRef</code> instance that is created of an
     * implementation-specific class corresponding to the external ref
     * type name returned by <code>readUTF</code>, and then
     * the <code>readExternal</code> method is invoked on
     * this object's <code>ref</code> field.
     * If the external ref type name is
     * <code>'UnicastRef'</code>, <code>'UnicastServerRef'</code>,
     * <code>'UnicastRef2'</code>, <code>'UnicastServerRef2'</code>,
     * or <code>'ActivatableRef'</code>, a corresponding
     * implementation-specific class must be found, and its
     * <code>readExternal</code> method must read the serial data
     * for that external ref type name as specified to be written
     * in the <b>serialData</b> documentation for this class.
     * If the external ref type name is any other string (of non-zero
     * length), a <code>ClassNotFoundException</code> will be thrown,
     * unless the implementation provides an implementation-specific
     * class corresponding to that external ref type name, in which
     * case this object's <code>ref</code> field will be set to an
     * instance of that implementation-specific class.
     */
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException {
    String refClassName = in.readUTF();
    if (refClassName == null || refClassName.length() == 0) {
        ref = (RemoteRef) in.readObject();
    } else {
        String internalRefClassName = RemoteRef.packagePrefix + '.' + refClassName;
        Class refClass = Class.forName(internalRefClassName);
        try {
            ref = (RemoteRef) refClass.newInstance();
        } catch (InstantiationException e) {
            throw new ClassNotFoundException(internalRefClassName, e);
        } catch (IllegalAccessException e) {
            throw new ClassNotFoundException(internalRefClassName, e);
        } catch (ClassCastException e) {
            throw new ClassNotFoundException(internalRefClassName, e);
        }
        ref.readExternal(in);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

javax.management.loading.DefaultLoaderRepository.load(ClassLoader, String)

private static Class load(ClassLoader without, String className) throws ClassNotFoundException {
    final List mbsList = MBeanServerFactory.findMBeanServer(null);
    for (Iterator it = mbsList.iterator(); it.hasNext(); ) {
        MBeanServer mbs = (MBeanServer) it.next();
        ClassLoaderRepository clr = mbs.getClassLoaderRepository();
        try {
            return clr.loadClassWithout(without, className);
        } catch (ClassNotFoundException e) {
        }
    }
    throw new ClassNotFoundException(className);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

javax.management.loading.MLet.findClass(String, ClassLoaderRepository)

/**
      * Called by {@link MLet#findClass(java.lang.String)}.
      * @param name The name of the class that we want to load/find.
      * @param clr The ClassLoaderRepository that can be used to search
      *            for the given class. This parameter is 
      *            <code>null</code> when called from within the
      *            {@link javax.management.MBeanServerFactory#getClassLoaderRepository(javax.management.MBeanServer) Class Loader Repository}.
      * @exception ClassNotFoundException The specified class could not be 
      *            found.
      **/
Class findClass(String name, ClassLoaderRepository clr) throws ClassNotFoundException {
    Class c = null;
    if (isTraceOn()) {
        trace('findClass', name);
    }
    try {
        c = super.findClass(name);
        if (isTraceOn()) {
            trace('findClass', 'Class ' + name + ' loaded through mlet classloader');
        }
    } catch (ClassNotFoundException e) {
        debug('findClass', 'Class ' + name + ' not found locally.');
    }
    if (c == null && delegateToCLR && clr != null) {
        try {
            debug('findClass', 'Class ' + name + ': looking in CLR');
            c = clr.loadClassBefore(this, name);
            if (isTraceOn()) {
                trace('findClass', 'Class ' + name + ' loaded through the default classloader repository');
            }
        } catch (ClassNotFoundException e) {
            debug('findClass', 'Class ' + name + ' not found in CLR.');
        }
    }
    if (c == null) {
        debug('findClass', 'Failed to load class ' + name);
        throw new ClassNotFoundException(name);
    }
    return c;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

javax.management.loading.MLetObjectInputStream.resolveClass(ObjectStreamClass)

/**
     * Use the given ClassLoader rather than using the system class
     */
protected Class resolveClass(ObjectStreamClass objectstreamclass) throws IOException, ClassNotFoundException {
    String s = objectstreamclass.getName();
    if (s.startsWith('[')) {
        int i;
        for (i = 1; s.charAt(i) == '['; i++) ;
        Class class1;
        if (s.charAt(i) == 'L') {
            class1 = loader.loadClass(s.substring(i + 1, s.length() - 1));
        } else {
            if (s.length() != i + 1) throw new ClassNotFoundException(s);
            class1 = primitiveType(s.charAt(i));
        }
        int ai[] = new int[i];
        for (int j = 0; j < i; j++) ai[j] = 0;
        return Array.newInstance(class1, ai).getClass();
    } else {
        return loader.loadClass(s);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

javax.management.modelmbean.RequiredModelMBean.loadClass(String)

private Class loadClass(String className) throws ClassNotFoundException {
    try {
        return Class.forName(className);
    } catch (ClassNotFoundException e) {
        final ClassLoaderRepository clr = getClassLoaderRepository();
        if (clr == null) throw new ClassNotFoundException(className);
        return clr.loadClass(className);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

javax.management.remote.rmi.NoCallStackClassLoader.findClass(String)

protected Class findClass(String name) throws ClassNotFoundException {
    for (int i = 0; i < classNames.length; i++) {
        if (name.equals(classNames[i])) {
            return defineClass(classNames[i], byteCodes[i], 0, byteCodes[i].length, protectionDomain);
        }
    }
    if (referencedClassLoader != null) {
        for (int i = 0; i < referencedClassNames.length; i++) {
            if (name.equals(referencedClassNames[i])) return referencedClassLoader.loadClass(name);
        }
    }
    throw new ClassNotFoundException(name);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.beans.Beans.instantiate(ClassLoader, String, BeanContext, AppletInitializer)

/**
     * Instantiate a bean.
     * The bean is created based on a name relative to a class-loader.
     * This name should be a dot-separated name such as 'a.b.c'.
     * In Beans 1.0 the given name can indicate either a serialized object
     * or a class.  Other mechanisms may be added in the future.  In
     * beans 1.0 we first try to treat the beanName as a serialized object
     * name then as a class name.
     * When using the beanName as a serialized object name we convert the
     * given beanName to a resource pathname and add a trailing '.ser' suffix.
     * We then try to load a serialized object from that resource.
     * For example, given a beanName of 'x.y', Beans.instantiate would first
     * try to read a serialized object from the resource 'x/y.ser' and if
     * that failed it would try to load the class 'x.y' and create an
     * instance of that class.
     * If the bean is a subtype of java.applet.Applet, then it is given
     * some special initialization.  First, it is supplied with a default
     * AppletStub and AppletContext.  Second, if it was instantiated from
     * a classname the applet's 'init' method is called.  (If the bean was
     * deserialized this step is skipped.)
     * Note that for beans which are applets, it is the caller's responsiblity
     * to call 'start' on the applet.  For correct behaviour, this should be done
     * after the applet has been added into a visible AWT container.
     * Note that applets created via beans.instantiate run in a slightly
     * different environment than applets running inside browsers.  In
     * particular, bean applets have no access to 'parameters', so they may
     * wish to provide property get/set methods to set parameter values.  We
     * advise bean-applet developers to test their bean-applets against both
     * the JDK appletviewer (for a reference browser environment) and the
     * BDK BeanBox (for a reference bean container).
     * @param     cls         the class-loader from which we should create
     *                 the bean.  If this is null, then the system
     *                        class-loader is used.
     * @param     beanName    the name of the bean within the class-loader.
     *                  For example 'sun.beanbox.foobah'
     * @param     beanContext The BeanContext in which to nest the new bean
     * @param     initializer The AppletInitializer for the new bean
     * @exception java.lang.ClassNotFoundException if the class of a serialized
     *              object could not be found.
     * @exception java.io.IOException if an I/O error occurs.
     */
public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext, AppletInitializer initializer) throws java.io.IOException, ClassNotFoundException {
    java.io.InputStream ins;
    java.io.ObjectInputStream oins = null;
    Object result = null;
    boolean serialized = false;
    java.io.IOException serex = null;
    if (cls == null) {
        try {
            cls = ClassLoader.getSystemClassLoader();
        } catch (SecurityException ex) {
        }
    }
    final String serName = beanName.replace('.', '/').concat('.ser');
    final ClassLoader loader = cls;
    ins = (InputStream) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

        public Object run() {
            if (loader == null) return ClassLoader.getSystemResourceAsStream(serName); else return loader.getResourceAsStream(serName);
        }
    });
    if (ins != null) {
        try {
            if (cls == null) {
                oins = new ObjectInputStream(ins);
            } else {
                oins = new ObjectInputStreamWithLoader(ins, cls);
            }
            result = oins.readObject();
            serialized = true;
            oins.close();
        } catch (java.io.IOException ex) {
            ins.close();
            serex = ex;
        } catch (ClassNotFoundException ex) {
            ins.close();
            throw ex;
        }
    }
    if (result == null) {
        Class cl;
        try {
            if (cls == null) {
                cl = Class.forName(beanName);
            } else {
                cl = cls.loadClass(beanName);
            }
        } catch (ClassNotFoundException ex) {
            if (serex != null) {
                throw serex;
            }
            throw ex;
        }
        try {
            result = cl.newInstance();
        } catch (Exception ex) {
            throw new ClassNotFoundException('' + cl + ' : ' + ex, ex);
        }
    }
    if (result != null) {
        AppletStub stub = null;
        if (result instanceof Applet) {
            Applet applet = (Applet) result;
            boolean needDummies = initializer == null;
            if (needDummies) {
                final String resourceName;
                if (serialized) {
                    resourceName = beanName.replace('.', '/').concat('.ser');
                } else {
                    resourceName = beanName.replace('.', '/').concat('.class');
                }
                URL objectUrl = null;
                URL codeBase = null;
                URL docBase = null;
                final ClassLoader cloader = cls;
                objectUrl = (URL) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

                    public Object run() {
                        if (cloader == null) return ClassLoader.getSystemResource(resourceName); else return cloader.getResource(resourceName);
                    }
                });
                if (objectUrl != null) {
                    String s = objectUrl.toExternalForm();
                    if (s.endsWith(resourceName)) {
                        int ix = s.length() - resourceName.length();
                        codeBase = new URL(s.substring(0, ix));
                        docBase = codeBase;
                        ix = s.lastIndexOf('/');
                        if (ix >= 0) {
                            docBase = new URL(s.substring(0, ix + 1));
                        }
                    }
                }
                BeansAppletContext context = new BeansAppletContext(applet);
                stub = (AppletStub) new BeansAppletStub(applet, context, codeBase, docBase);
                applet.setStub(stub);
            } else {
                initializer.initialize(applet, beanContext);
            }
            if (beanContext != null) {
                beanContext.add(result);
            }
            if (!serialized) {
                applet.setSize(100, 100);
                applet.init();
            }
            if (needDummies) {
                ((BeansAppletStub) stub).active = true;
            } else initializer.activate(applet);
        } else if (beanContext != null) beanContext.add(result);
    }
    return result;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.security.CodeSource.readObject(java.io.ObjectInputStream)

/**
     * Restores this object from a stream (i.e., deserializes it).
     */
private synchronized void readObject(java.io.ObjectInputStream ois) throws IOException, ClassNotFoundException {
    CertificateFactory cf;
    Hashtable cfs = null;
    ois.defaultReadObject();
    int size = ois.readInt();
    if (size > 0) {
        cfs = new Hashtable(3);
        this.certs = new java.security.cert.Certificate[size];
    }
    for (int i = 0; i < size; i++) {
        String certType = ois.readUTF();
        if (cfs.containsKey(certType)) {
            cf = (CertificateFactory) cfs.get(certType);
        } else {
            try {
                cf = CertificateFactory.getInstance(certType);
            } catch (CertificateException ce) {
                throw new ClassNotFoundException('Certificate factory for ' + certType + ' not found');
            }
            cfs.put(certType, cf);
        }
        byte[] encoded = null;
        try {
            encoded = new byte[ois.readInt()];
        } catch (OutOfMemoryError oome) {
            throw new IOException('Certificate too big');
        }
        ois.readFully(encoded);
        ByteArrayInputStream bais = new ByteArrayInputStream(encoded);
        try {
            this.certs[i] = cf.generateCertificate(bais);
        } catch (CertificateException ce) {
            throw new IOException(ce.getMessage());
        }
        bais.close();
    }
    try {
        this.signers = (CodeSigner[]) ois.readObject();
    } catch (IOException ioe) {
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.security.UnresolvedPermission.readObject(java.io.ObjectInputStream)

/**
     * Restores this object from a stream (i.e., deserializes it).
     */
private synchronized void readObject(java.io.ObjectInputStream ois) throws IOException, ClassNotFoundException {
    CertificateFactory cf;
    Hashtable cfs = null;
    ois.defaultReadObject();
    if (type == null) throw new NullPointerException('type can't be null');
    int size = ois.readInt();
    if (size > 0) {
        cfs = new Hashtable(3);
        this.certs = new java.security.cert.Certificate[size];
    }
    for (int i = 0; i < size; i++) {
        String certType = ois.readUTF();
        if (cfs.containsKey(certType)) {
            cf = (CertificateFactory) cfs.get(certType);
        } else {
            try {
                cf = CertificateFactory.getInstance(certType);
            } catch (CertificateException ce) {
                throw new ClassNotFoundException('Certificate factory for ' + certType + ' not found');
            }
            cfs.put(certType, cf);
        }
        byte[] encoded = null;
        try {
            encoded = new byte[ois.readInt()];
        } catch (OutOfMemoryError oome) {
            throw new IOException('Certificate too big');
        }
        ois.readFully(encoded);
        ByteArrayInputStream bais = new ByteArrayInputStream(encoded);
        try {
            this.certs[i] = cf.generateCertificate(bais);
        } catch (CertificateException ce) {
            throw new IOException(ce.getMessage());
        }
        bais.close();
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.io.ObjectInputStream.readNonProxyDesc(boolean)

/**
     * Reads in and returns class descriptor for a class that is not a dynamic
     * proxy class.  Sets passHandle to class descriptor's assigned handle.  If
     * class descriptor cannot be resolved to a class in the local VM, a
     * ClassNotFoundException is associated with the descriptor's handle.
     */
private ObjectStreamClass readNonProxyDesc(boolean unshared) throws IOException {
    if (bin.readByte() != TC_CLASSDESC) {
        throw new StreamCorruptedException();
    }
    ObjectStreamClass desc = new ObjectStreamClass();
    int descHandle = handles.assign(unshared ? unsharedMarker : desc);
    passHandle = NULL_HANDLE;
    ObjectStreamClass readDesc = null;
    try {
        readDesc = readClassDescriptor();
    } catch (ClassNotFoundException ex) {
        throw (IOException) new InvalidClassException('failed to read class descriptor').initCause(ex);
    }
    Class cl = null;
    ClassNotFoundException resolveEx = null;
    bin.setBlockDataMode(true);
    try {
        if ((cl = resolveClass(readDesc)) == null) {
            throw new ClassNotFoundException('null class');
        }
    } catch (ClassNotFoundException ex) {
        resolveEx = ex;
    }
    skipCustomData();
    desc.initNonProxy(readDesc, cl, resolveEx, readClassDesc(false));
    handles.finish(descHandle);
    passHandle = descHandle;
    return desc;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.io.ObjectInputStream.readProxyDesc(boolean)

/**
     * Reads in and returns class descriptor for a dynamic proxy class.  Sets
     * passHandle to proxy class descriptor's assigned handle.  If proxy class
     * descriptor cannot be resolved to a class in the local VM, a
     * ClassNotFoundException is associated with the descriptor's handle.
     */
private ObjectStreamClass readProxyDesc(boolean unshared) throws IOException {
    if (bin.readByte() != TC_PROXYCLASSDESC) {
        throw new StreamCorruptedException();
    }
    ObjectStreamClass desc = new ObjectStreamClass();
    int descHandle = handles.assign(unshared ? unsharedMarker : desc);
    passHandle = NULL_HANDLE;
    int numIfaces = bin.readInt();
    String[] ifaces = new String[numIfaces];
    for (int i = 0; i < numIfaces; i++) {
        ifaces[i] = bin.readUTF();
    }
    Class cl = null;
    ClassNotFoundException resolveEx = null;
    bin.setBlockDataMode(true);
    try {
        if ((cl = resolveProxyClass(ifaces)) == null) {
            throw new ClassNotFoundException('null class');
        }
    } catch (ClassNotFoundException ex) {
        resolveEx = ex;
    }
    skipCustomData();
    desc.initProxy(cl, resolveEx, readClassDesc(false));
    handles.finish(descHandle);
    passHandle = descHandle;
    return desc;
}

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