VinodAnandan / sonar-pitest

43 stars 30 forks source link

Computing Portfolio fails due to Pitest plugin #25

Open johankees opened 6 years ago

johankees commented 6 years ago

Hi,

With SonarQube v6.7 we see issues with computing portfolios when the pitest plugin is installed. The background task fails with the following error: org.sonar.server.computation.task.projectanalysis.component.VisitException: Visit of Component {key=KEY_NAME,type=VIEW} failed ..... Caused by: java.lang.IllegalStateException: Value can not be converted to int because current value type is a DOUBLE at org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureImpl.checkValueType(MeasureImpl.java:80) at org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureImpl.getIntValue(MeasureImpl.java:50) at org.sonar.plugins.pitest.PitestComputer.compute(PitestComputer.java:79) at org.sonar.plugins.pitest.PitestComputer.compute(PitestComputer.java:57)

Odd thing is that this happens for nested portfolios, but not for single portfolios. For example, this will work file PortfolioA

But this fails Portfolio1 <-- Fails here

Here portfolio A and the configured projects are the same in both cases. It will fail on the top level portfolio btw (Portfolio1).

johankees commented 6 years ago

As per SonarSource support: Alexandre GigleuxToday 4:11 PM I looked at the code of the Pitest Plugin. At some point it is doing the sum (https://github.com/VinodAnandan/sonar-pitest/blob/master/src/main/java/org/sonar/plugins/pitest/PitestComputer.java#L79) of some metrics (https://github.com/VinodAnandan/sonar-pitest/blob/master/src/main/java/org/sonar/plugins/pitest/PitestComputer.java#L37). To run this code, the metric must be declared with the Metric.ValueType.INT type. According to me, the problem is coming from this line: https://github.com/VinodAnandan/sonar-pitest/blob/master/src/main/java/org/sonar/plugins/pitest/PitestComputer.java#L43 The metric MUTATIONS_DATA_KEY is declared as Metric.ValueType.DATA, so there is no way to convert it to an Int to run the sum. I let you see that with the maintainer of the plugin by raising an Issue here: https://github.com/VinodAnandan/sonar-pitest/issues Regards

johankees commented 6 years ago

Since the error is about expecting an int and getting a double, my guess would be that the issue is with MUTATIONS_KILLED_RATIO / MUTATIONS_KILLED_PERCENT_KEY, since Metric.ValueType.PERCENT is of type Double

bradflood commented 6 years ago

@johankees I will fix this when I return from vacation next week.

johankees commented 6 years ago

Thanks @bradflood FYI, I checked this a bit more and added some logging to find out where it breaks. I got the following in the logs: 2018.01.03 14:13:59 ERROR ce[AWC8Xwyl3Nc2CAfF_Hx3][o.s.p.p.PitestComputer] Failed to compute value for pitest_mutations_killed_percent.

For now I've "fixed" this by surrounding "sum += m.getIntValue();" with a try/catch clause, which allowed me to log the above statement.

Hope this helps... Thanks!

bradflood commented 6 years ago

@johankees great! it looks as if you have a handle on what needs to be fixed, and have built the code. If you want to attempt a fix, that would be great. Send a pull request and we can review it together.

bradflood commented 6 years ago

PR 26 submitted and merged to catch IllegalStateException when metric is of type Double (as is the case when the metric is killed percent). This issue is kept open until a more general solution is in place. Specifically, we cannot assume that all metrics in the list are integers; when a Portfolio is being computed, a percentage killed will have been calculated and added to the list. Need a deeper understanding that is reflected in PitestComputer and corresponding test.