Committed by
Gerrit Code Review
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
Showing
1 changed file
with
3 additions
and
1 deletions
| ... | @@ -52,7 +52,9 @@ public class ImmutableClassChecker { | ... | @@ -52,7 +52,9 @@ public class ImmutableClassChecker { |
| 52 | 52 | ||
| 53 | // class must have only final and private data members | 53 | // class must have only final and private data members |
| 54 | for (final Field field : clazz.getDeclaredFields()) { | 54 | for (final Field field : clazz.getDeclaredFields()) { |
| 55 | - if (field.getName().startsWith("__cobertura")) { | 55 | + if (field.getName().startsWith("_") || |
| 56 | + field.getName().startsWith("$")) { | ||
| 57 | + // eclipse generated code may insert switch table - ignore | ||
| 56 | // cobertura sticks these fields into classes - ignore them | 58 | // cobertura sticks these fields into classes - ignore them |
| 57 | continue; | 59 | continue; |
| 58 | } | 60 | } | ... | ... |
-
Please register or login to post a comment