summaryrefslogtreecommitdiffstats
path: root/tests/pureJava/FinalStaticField.java
blob: b1ae60dc551cedff5d3173c74784e688b5874ebb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.lang.reflect.*;
import org.aspectj.testing.Tester;


class C{}

class D {
    public static final C public_c = new C();
    private static final C private_c = new C();
    protected static final C protected_c = new C();
    static final C default_c = new C();
}

/** @testcase PR#866 final static fields not marked as such in binaries */
public class FinalStaticField {
    public static final String[] FIELDS = new String[]
        { "public_c", "private_c", "protected_c", "default_c" };
    
    public static void main(String[] args) {

        Tester.expectEvents(FIELDS);

        Field[] fields = D.class.getDeclaredFields();
        StringBuffer failures = new StringBuffer();
        for (int i = 0; i < fields.length; i++) {
            String fieldName = fields[i].getName();
            Tester.event(fieldName);
			if (!fieldName.endsWith("_c")) {
                Tester.check(false, "unexpected field: " + fieldName);
            } else if (!(Modifier.isFinal(fields[i].getModifiers()))) {
                failures.append(fieldName + " ");
            }
        }
        Tester.checkAllEvents();
        if (0 < failures.length()) {
            Tester.check(false, failures.toString());
        }
    }
}