#vulnerable code 
                              @Test(timeout = 1000)
  public void testSingleTask() throws Exception {
    final TimeoutScheduler scheduler = TimeoutScheduler.newInstance(1);
    final TimeDuration grace = TimeDuration.valueOf(100, TimeUnit.MILLISECONDS);
    scheduler.setGracePeriod(grace);
    Assert.assertFalse(scheduler.hasScheduler());

    final ErrorHandler errorHandler = new ErrorHandler();

    final AtomicBoolean fired = new AtomicBoolean(false);
    scheduler.onTimeout(TimeDuration.valueOf(250, TimeUnit.MILLISECONDS), () -> {
      Assert.assertFalse(fired.get());
      fired.set(true);
    }, errorHandler);
    Assert.assertTrue(scheduler.hasScheduler());

    Thread.sleep(100);
    Assert.assertFalse(fired.get());
    Assert.assertTrue(scheduler.hasScheduler());

    Thread.sleep(100);
    Assert.assertFalse(fired.get());
    Assert.assertTrue(scheduler.hasScheduler());

    Thread.sleep(100);
    Assert.assertTrue(fired.get());
    Assert.assertTrue(scheduler.hasScheduler());

    Thread.sleep(100);
    Assert.assertTrue(fired.get());
    Assert.assertFalse(scheduler.hasScheduler());

    errorHandler.assertNoError();
  } 
                            #location 6 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                              @Test(timeout = 1000)
  public void testSingleTask() throws Exception {
    final TimeoutScheduler scheduler = TimeoutScheduler.newInstance();
    final TimeDuration grace = TimeDuration.valueOf(100, TimeUnit.MILLISECONDS);
    scheduler.setGracePeriod(grace);
    Assert.assertFalse(scheduler.hasScheduler());

    final ErrorHandler errorHandler = new ErrorHandler();

    final AtomicBoolean fired = new AtomicBoolean(false);
    scheduler.onTimeout(TimeDuration.valueOf(250, TimeUnit.MILLISECONDS), () -> {
      Assert.assertFalse(fired.get());
      fired.set(true);
    }, errorHandler);
    Assert.assertTrue(scheduler.hasScheduler());

    Thread.sleep(100);
    Assert.assertFalse(fired.get());
    Assert.assertTrue(scheduler.hasScheduler());

    Thread.sleep(100);
    Assert.assertFalse(fired.get());
    Assert.assertTrue(scheduler.hasScheduler());

    Thread.sleep(100);
    Assert.assertTrue(fired.get());
    Assert.assertTrue(scheduler.hasScheduler());

    Thread.sleep(100);
    Assert.assertTrue(fired.get());
    Assert.assertFalse(scheduler.hasScheduler());

    errorHandler.assertNoError();
    scheduler.setGracePeriod(grace);
  }