Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Security manager checks may be allowed to get bypassed depending on the immediate caller's class loader. When an API (see table below) is invoked on a class object, a comparison is run between the immediate caller's class loader and that of the class object. The class object is the object on which an API is invoked. For instance, in the presence of a security manager, the getSystemClassLoader and getParent methods succeed only if the caller's class loader is the delegation ancestor of the current class loader or if the caller's class loader is the same as the current one or if the code in the current execution context has the RunTimePermission, namely "getClassLoader".

...

Code Block
bgColor#FFcccc
public class ExceptionExample
 {
   public static void untrustedCode() {
     Date now = new Date();
     Class<?> dateClass = now.getClass();
     createInstance(dateClass);
    }

    public static void createInstance(Class<?> dateClass)
    {
      try { // Create another Date object using the Date Class
            Object o = dateClass.newInstance();
            if (o instanceof Date) {
              Date d = (Date)o;
              System.out.println("The time is: " + d.toString());
             }
       }
       catch (InstantiationException ie) { System.out.println(ie.toString()); }
       catch (IllegalAccessException iae) { System.out.println(iae.toString()); }    	
    }
}

...