I am getting the below error when running the clover test. Same test runs fine during the unit test.
This is happening when i am trying to copy an object using reflection.
Do we have any work around for this issue.
Clover Version:4.0.2
Error:
Caused by: java.lang.IllegalAccessException: Can not set static final com_atlassian_clover.TestNameSniffer field <<XXX Class>>.__CLR4_0_2_TEST_NAME_SNIFFER to com_atlassian_clover.TestNameSniffer$1
at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:76)
at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:80)
at sun.reflect.UnsafeQualifiedStaticObjectFieldAccessorImpl.set(UnsafeQualifiedStaticObjectFieldAccessorImpl.java:77)
at java.lang.reflect.Field.set(Field.java:764)
Code that copies the object:
Class<? extends Object> copy1 = entity.getClass();
Class<? extends Object> copy2 = entity2.getClass();
Field[] fromFields = copy1.getDeclaredFields();
Field[] toFields = copy2.getDeclaredFields();
Object value = null;
for (Field field : fromFields) {
Field field1 = copy2.getDeclaredField(field.getName());
value = field.get(entity);
field1.set(entity2, value);
}
Thanks Marek. This worked
As you can see in the exception message, you're trying to write to a static final field.
Change your copying method to skip fields of type TestNameSniffer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.