<?xml version="1.0" encoding="UTF-8"?>
<test-data
        xmlns="http://pmd.sourceforge.net/rule-tests"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">

    <test-code>
        <description>simple failure case</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>3</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    void foo () {
        finalize();
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>calling finalize on an object</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>4</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    void foo () {
        Foo f;
        f.finalize();
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>calling super.finalize</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>3</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    void foo () {
        super.finalize();
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>no call to finalize</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    void finalize () {
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>it's ok in a finalizer</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    void finalize () {
        super.finalize();
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>finalizer in anon inner class is OK too</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    void foo () {
        Foo myFoo = new Foo(new FooOtherInterface() {
            protected void finalize() {
                super.finalize();
            }
        });
    }

    interface FooOtherInterface { }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>#1440 NPE in AvoidCallingFinalize</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>3</expected-linenumbers>
        <code><![CDATA[
public class InputFinalize {
    {
        super.finalize();
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>overloaded finalize is ok</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    public void foo() {
        finalize("hello", "world");
    }

    public void finalize(String ... args) {}
}
        ]]></code>
    </test-code>

    <test-code>
        <description>variable name false-positive test</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
    private int finalize;

    public void bar() {
        finalize++;
        return finalize;
    }
}
        ]]></code>
    </test-code>

    <test-code>
        <description>super.finalize in constructor false-negative test</description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>4</expected-linenumbers>
        <code><![CDATA[
public class Foo {
    public Foo() throws Throwable {
        super.equals(new String());
        super.finalize();
    }
}
        ]]></code>
    </test-code>
</test-data>
