|) – with Java's short circuiting, what's the forth condition JaCoCo wants me to cover?

This is probably a rather simple question, but I’m at a loss…

I have an if statement like the following:

if(TheEnum.A.equals(myEnum) || TheEnum.B.equals(myEnum))

TheEnum can be A, B, C, … G (more than just 4 options).

JaCoCo (SONAR) tells me that there are four conditions I can cover here.Which ones are those?Isn’t the entire set I can test for in this instance essentially

if(true || not_evaluated) => true
if(false || true) => true
if(false || false) => false

I’m pretty sure I can’t specifically test forif(true || true) orif(true || false),as short circuit evaluation won’t get that far…?

If so, what is the forth option JaCoCo

解决方案:

You are right, this code is short-circuiting. It’s compiled into bytecode roughly like this (assuming Java has goto):

if(TheEnum.A.equals(myEnum)) goto ok;
if(!TheEnum.B.equals(myEnum)) goto end;
ok:
   // body of if statement
end:

So as JaCoCo analyzes the bytecode, from its point of view you have the two independent checks: first if and second if, which generate four possible branches. You may consider this as a JaCoCo bug, but I guess it’s not very easy to fix this robustly and it is not very disturbing, so you can live with it.

给TA打赏
共{{data.count}}人
人已打赏
未分类

从不同行数的数据中,在同一图表上绘制两条线的ggplot

2022-9-9 6:03:17

未分类

Python:如何在pandas数据框中基于delta时间选择行?

2022-9-9 6:03:19

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索