Friday, March 13, 2015



InstantiationException is described in the javadoc comments as:

Thrown when an application tries to create an instance of a class using the newInstance method in class Class, but the specified class object cannot be instantiated because it is an interface or is an abstract class.
author: unascribed version: 1.17, 12/19/03 see: java.lang.Class#newInstance() 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.


private T newInstance0() throws InstantiationException, IllegalAccessException {
    if (cachedConstructor == null) {
        if (this == Class.class) {
            throw new IllegalAccessException('Can not call newInstance() on the Class for java.lang.Class');
        try {
            Class[] empty = {};
            final Constructor<T> c = getConstructor0(empty, Member.DECLARED);

                public Object run() {
                    return null;
            cachedConstructor = c;
        } catch (NoSuchMethodException e) {
            throw new InstantiationException(getName());
    Constructor<T> tmpConstructor = cachedConstructor;
    int modifiers = tmpConstructor.getModifiers();
    if (!Reflection.quickCheckMemberAccess(this, modifiers)) {
        Class caller = Reflection.getCallerClass(3);
        if (newInstanceCallerCache != caller) {
            Reflection.ensureMemberAccess(caller, this, null, modifiers);
            newInstanceCallerCache = caller;
    try {
        return tmpConstructor.newInstance((Object[]) null);
    } catch (InvocationTargetException e) {
        return null;

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at:

No comments:

Post a Comment