Exclude generated fields from ImmutableClass check
- Eclipse sometimes auto-generates switch table, which fails the immutability unit tests.
Ignore field name starting with _ or $, which tends to be used for auto-generated names.
----
Failed tests:
IpAddressTest.testImmutable:41
Expected: is "a properly defined immutable class"
but : was "a field named '$SWITCH_TABLE$org$onlab$packet$IpAddress$Version' that is not final"
IpPrefixTest.testImmutable:39
Expected: is "a properly defined immutable class"
but : was "a field named '$SWITCH_TABLE$org$onlab$packet$IpAddress$Version' that is not final"
----
Change-Id: Ibca5f61b9ca6b6006424a4288f1863b6e60ad484
diff --git a/utils/junit/src/main/java/org/onlab/junit/ImmutableClassChecker.java b/utils/junit/src/main/java/org/onlab/junit/ImmutableClassChecker.java
index 421a3e9..f2dbb3f 100644
--- a/utils/junit/src/main/java/org/onlab/junit/ImmutableClassChecker.java
+++ b/utils/junit/src/main/java/org/onlab/junit/ImmutableClassChecker.java
@@ -52,7 +52,9 @@
// class must have only final and private data members
for (final Field field : clazz.getDeclaredFields()) {
- if (field.getName().startsWith("__cobertura")) {
+ if (field.getName().startsWith("_") ||
+ field.getName().startsWith("$")) {
+ // eclipse generated code may insert switch table - ignore
// cobertura sticks these fields into classes - ignore them
continue;
}