You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FinalStaticField.java 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import java.lang.reflect.*;
  2. import org.aspectj.testing.Tester;
  3. class C{}
  4. class D {
  5. public static final C public_c = new C();
  6. private static final C private_c = new C();
  7. protected static final C protected_c = new C();
  8. static final C default_c = new C();
  9. }
  10. /** @testcase PR#866 final static fields not marked as such in binaries */
  11. public class FinalStaticField {
  12. public static final String[] FIELDS = new String[]
  13. { "public_c", "private_c", "protected_c", "default_c" };
  14. public static void main(String[] args) {
  15. Tester.expectEvents(FIELDS);
  16. Field[] fields = D.class.getDeclaredFields();
  17. StringBuffer failures = new StringBuffer();
  18. for (int i = 0; i < fields.length; i++) {
  19. String fieldName = fields[i].getName();
  20. Tester.event(fieldName);
  21. if (!fieldName.endsWith("_c")) {
  22. Tester.check(false, "unexpected field: " + fieldName);
  23. } else if (!(Modifier.isFinal(fields[i].getModifiers()))) {
  24. failures.append(fieldName + " ");
  25. }
  26. }
  27. Tester.checkAllEvents();
  28. if (0 < failures.length()) {
  29. Tester.check(false, failures.toString());
  30. }
  31. }
  32. }