jtulach@368: package org.apidesign.cloneproblem; jtulach@368: jtulach@368: import java.util.Date; jtulach@368: import junit.framework.TestCase; jtulach@368: jtulach@368: /** Test that would be written by the API hacker. jtulach@368: * jtulach@368: * @author Jaroslav Tulach jtulach@368: */ jtulach@368: public class ExploitTest extends TestCase { jtulach@368: public ExploitTest(String name) { jtulach@368: super(name); jtulach@368: } jtulach@368: jtulach@368: public void testExploitOverridableClone() { jtulach@368: try { jtulach@368: HackedDate now = new HackedDate(); jtulach@368: HackedDate later = new HackedDate(now.getTime() + 1000); jtulach@368: jtulach@368: Interval interval = new Interval(now, later); jtulach@368: assertEquals("1s", 1000, interval.getLength()); jtulach@368: jtulach@368: fail("And I hoped NullPointerException will be thrown!"); jtulach@368: } catch (NullPointerException ex) { jtulach@368: // success, the quest is to generate NullPointerException! jtulach@368: } jtulach@368: } jtulach@368: jtulach@368: // BEGIN: interval.exploit jtulach@368: private static class HackedDate extends Date { jtulach@368: public HackedDate() { jtulach@368: } jtulach@368: jtulach@368: public HackedDate(long date) { jtulach@368: super(date); jtulach@368: } jtulach@368: jtulach@368: @Override jtulach@368: public Object clone() { jtulach@368: return null; jtulach@368: } jtulach@368: } jtulach@368: // END: interval.exploit jtulach@368: }