From the FAQ (http://www.eclemma.org/jacoco/trunk/doc/faq.html):

Q: My code uses reflection. Why does it fail when I execute it with JaCoCo?

A: To collect execution data JaCoCo instruments the classes under test which adds two members to the classes: A private static field $jacocoData and a private static method $jacocoInit(). Both members are marked as synthetic. Please change your code to ignore synthetic members. This is a good practice anyways as also the Java compiler creates synthetic members in certain situation.


So in your particular case you will probably add the following check:

if (!fie.isSynthetic()) {
  Object fvalue = getFieldValue(fie, vo);
  request.setAttribute(fie.getName(), fvalue);
}


Regards,
-marc



On 2015-04-15 04:13, Steven wrote:
Hi All,
 I use reflection in code as follow:

 public static void setFormFieldsToRequest(Object vo,
 HttpServletRequest request) throws Exception {
 Field[] fields = vo.getClass().getDeclaredFields();
 Field fie = null;
 for (int i = 0; i < fields.length; i++) {
 fie = fields[i];
 if (fie.getName().equals("serialVersionUID"))
 continue;
 else {
 Object fvalue = getFieldValue(fie, vo);
 request.setAttribute(fie.getName(), fvalue);
 }
 }
 }
It throwed the follow exception:

 at Caused by: java.lang.Exception: can't process the type: class [Z
 at
com.test.web.ap.action.APActionUtil.getFieldValue(APActionUtil.java:301)
 at
com.test.web.ap.action.APActionUtil.setFormFieldsToRequest(APActionUtil.java:240)
 at

I viewed the section about reflection on FAQ page.
It may cause to get incorrect coverage if use reflection in code. But
the application fails to run now.

I know that it can exclude some packages by using the key word
'exclude='com.test.web.*'',
but if I have many those codes in different packages which may lead to
miscellaneous conf.

I want to exclude those codes that use reflection simply, any
suggestion ? Thanks.

 --
 You received this message because you are subscribed to the Google
Groups "JaCoCo and EclEmma Users" group.
 To unsubscribe from this group and stop receiving emails from it,
send an email to [email protected].
 To view this discussion on the web visit
https://groups.google.com/d/msgid/jacoco/92643cf7-e760-48b5-8860-97b4da69007c%40googlegroups.com
[1].
 For more options, visit https://groups.google.com/d/optout [2].


Links:
------
[1]
https://groups.google.com/d/msgid/jacoco/92643cf7-e760-48b5-8860-97b4da69007c%40googlegroups.com?utm_medium=email&utm_source=footer
[2] https://groups.google.com/d/optout

--
You received this message because you are subscribed to the Google Groups "JaCoCo 
and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/80e26586692a6ef3d9bb1e4c641e20bd%40mountainminds.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to