/[classpath]/classpath/java/lang/Class.java
ViewVC logotype

Diff of /classpath/java/lang/Class.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by cbj, Mon Apr 7 11:41:19 2003 UTC revision 1.8 by cbj, Thu Apr 17 12:32:29 2003 UTC
# Line 44  import java.lang.reflect.Field; Line 44  import java.lang.reflect.Field;
44  import java.lang.reflect.InvocationTargetException;  import java.lang.reflect.InvocationTargetException;
45  import java.lang.reflect.Member;  import java.lang.reflect.Member;
46  import java.lang.reflect.Method;  import java.lang.reflect.Method;
47    import java.lang.reflect.Modifier;
48  import java.net.URL;  import java.net.URL;
49  import java.security.AllPermission;  import java.security.AllPermission;
50  import java.security.Permissions;  import java.security.Permissions;
51  import java.security.ProtectionDomain;  import java.security.ProtectionDomain;
52    import java.security.AccessController;
53    import java.security.PrivilegedAction;
54  import java.util.ArrayList;  import java.util.ArrayList;
55  import java.util.Arrays;  import java.util.Arrays;
56  import java.util.HashMap;  import java.util.HashMap;
# Line 109  public final class Class implements Seri Line 112  public final class Class implements Seri
112    
113    transient final VMClass vmClass;    transient final VMClass vmClass;
114    
115      /** newInstance() caches the default constructor */
116      private transient Constructor constructor;
117    
118    /**    /**
119     * Class is non-instantiable from Java code; only the VM can create     * Class is non-instantiable from Java code; only the VM can create
120     * instances of this class.     * instances of this class.
# Line 233  public final class Class implements Seri Line 239  public final class Class implements Seri
239    public Object newInstance()    public Object newInstance()
240      throws InstantiationException, IllegalAccessException      throws InstantiationException, IllegalAccessException
241    {    {
242      try      memberAccessCheck(Member.PUBLIC);
243        Constructor constructor;
244        synchronized(this)
245        {        {
246          return getConstructor(null).newInstance(null);          constructor = this.constructor;
247        }        }
248      catch (IllegalArgumentException e)      if (constructor == null)
249        {        {
250          throw (Error) new InternalError("Should not happen").initCause(e);          Constructor[] constructors = getDeclaredConstructors(false);
251            for (int i = 0; i < constructors.length; i++)
252            {
253                if (constructors[i].getParameterTypes().length == 0)
254                {
255                    constructor = constructors[i];
256                    break;
257                }
258            }
259            if (constructor == null)
260                throw new InstantiationException(getName());
261        }        }
262      catch (InvocationTargetException e)      int modifiers = constructor.getModifiers();
263        if (!Modifier.isPublic(modifiers))
264        {        {
265          throw (InstantiationException)          Class caller = VMSecurityManager.getClassContext()[1];
266            new InstantiationException(e.toString()).initCause(e);          if (caller != this &&
267                (Modifier.isPrivate(modifiers) || getClassLoader() != caller.getClassLoader() ||
268                !ClassHelper.getPackagePortion(getName()).equals(ClassHelper.getPackagePortion(caller.getName()))))
269                throw new IllegalAccessException(getName() + " has an inaccessible constructor");
270            if (!constructor.isAccessible())
271              {
272                final Constructor finalConstructor = constructor;
273                AccessController.doPrivileged(new PrivilegedAction() {
274                    public Object run() {
275                        finalConstructor.setAccessible(true);
276                        return null;
277                    }
278                });
279                synchronized(this)
280                  {
281                    if (this.constructor == null)
282                        this.constructor = constructor;
283                  }
284              }
285        }        }
286      catch (NoSuchMethodException e)      try
287          {
288            return constructor.newInstance(null);
289          }
290        catch (InvocationTargetException e)
291        {        {
292          throw (InstantiationException)          VMClass.throwException(e.getTargetException());
293            new InstantiationException(e.toString()).initCause(e);          throw (InternalError) new InternalError("VMClass.throwException returned").initCause(e);
294        }        }
295    }    }
296    

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26