#vulnerable code 
                                @Test
    public void receiveMessages() throws Exception {
        final Project project = new FkProject();
        final Farm farm = new PropsFarm(new FkFarm(project));
        final AmazonSQS sqs = new ExtSqs(farm).value();
        final String queue = new ClaimsQueueUrl(farm).asString();
        final ClaimsSqs claims = new ClaimsSqs(sqs, queue, project);
        final List<Message> messages = new CopyOnWriteArrayList<>();
        final ClaimsRoutine routine = new ClaimsRoutine(
            farm,
            msgs -> {
                messages.addAll(msgs);
                new And(
                    (Message msg) -> sqs.deleteMessage(
                        queue, msg.getReceiptHandle()
                    ), msgs
                ).value();
            }
        );
        routine.start();
        TimeUnit.SECONDS.sleep((long) Tv.FIVE);
        final String type = "test";
        new ClaimOut()
            .type(type)
            .param("nonce", System.currentTimeMillis())
            .postTo(claims);
        TimeUnit.SECONDS.sleep((long) Tv.FIVE);
        routine.close();
        MatcherAssert.assertThat(
            "didn't receive",
            messages,
            Matchers.hasSize(1)
        );
        final Message message = messages.get(0);
        MatcherAssert.assertThat(
            "invalid project",
            new SqsProject(farm, message).pid(),
            Matchers.equalTo(project.pid())
        );
        final ClaimIn claim = new ClaimIn(
            new XMLDocument(message.getBody()).nodes("//claim").get(0)
        );
        MatcherAssert.assertThat(
            claim.type(),
            Matchers.equalTo(type)
        );
    } 
                            #location 29 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                @Test
    public void receiveMessages() throws Exception {
        final Project project = new FkProject();
        final Farm farm = new PropsFarm(new FkFarm(project));
        final AmazonSQS sqs = new ExtSqs(farm).value();
        final String queue = new ClaimsQueueUrl(farm).asString();
        final ClaimsSqs claims = new ClaimsSqs(sqs, queue, project);
        final List<Message> messages = new CopyOnWriteArrayList<>();
        final ClaimsRoutine routine = new ClaimsRoutine(
            farm,
            msgs -> {
                messages.addAll(msgs);
                new And(
                    (Message msg) -> sqs.deleteMessage(
                        queue, msg.getReceiptHandle()
                    ), msgs
                ).value();
            }
        );
        routine.start();
        TimeUnit.SECONDS.sleep((long) Tv.FIVE);
        final String type = "test";
        new ClaimOut()
            .type(type)
            .param("nonce1", System.nanoTime())
            .postTo(claims);
        new ClaimOut()
            .type("delayed")
            .until(Duration.ofMinutes(1L))
            .param("nonce2", System.nanoTime())
            .postTo(claims);
        TimeUnit.SECONDS.sleep((long) Tv.FIVE);
        routine.close();
        MatcherAssert.assertThat(
            "expected one message",
            messages,
            Matchers.hasSize(1)
        );
        final Message message = messages.get(0);
        MatcherAssert.assertThat(
            "invalid project",
            new SqsProject(farm, message).pid(),
            Matchers.equalTo(project.pid())
        );
        final ClaimIn claim = new ClaimIn(
            new XMLDocument(message.getBody()).nodes("//claim").get(0)
        );
        MatcherAssert.assertThat(
            claim.type(),
            Matchers.equalTo(type)
        );
    }