1 package org.apidesign.cloneproblem;
4 import junit.framework.TestCase;
6 /** Test that would be written by the API hacker.
8 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
10 public class ExploitTest extends TestCase {
11 public ExploitTest(String name) {
15 public void testExploitOverridableClone() {
17 HackedDate now = new HackedDate();
18 HackedDate later = new HackedDate(now.getTime() + 1000);
20 Interval interval = new Interval(now, later);
21 assertEquals("1s", 1000, interval.getLength());
23 fail("And I hoped NullPointerException will be thrown!");
24 } catch (NullPointerException ex) {
25 // success, the quest is to generate NullPointerException!
29 // BEGIN: interval.exploit
30 private static class HackedDate extends Date {
34 public HackedDate(long date) {
39 public Object clone() {
43 // END: interval.exploit