Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by NavBot

...

Wiki Markup
According to the Java Language Specification \[[JLS 05|AA. Java References#JLS 05]\] section 4.3.2 ""The Class {{Object}}"": ""The method {{getClass}} returns the {{Class}} object that represents the class of the object"". The first ten methods shown below can be used on a {{Class}} object.

...

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

    public static void createInstance(Class&lt;?&gt;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(&quot;"The time is: &quot;" + d.toString());
        }
      }
      catch (InstantiationException ie) { System.out.println(ie.toString()); }
      catch (IllegalAccessException iae) { System.out.println(iae.toString()); }    	
    }
}

...

SEC01-J. Provide sensitive mutable classes with unmodifiable wrappers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      02. Platform Security (SEC)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      SEC03-J. Do not use APIs that perform access checks against the immediate caller