mauricioaniche/ck

Incorrect CBO for Generic Classes

Closed this issue · 7 comments

Suppose we have a generic class Box. The CBO returns 2 for the following class:

public class Coupling6 {
    private Box<Integer> integerBox = new Box<Integer>();
}

However, I think it should return one.

CK indeed returns 1 here. See the test I just created for this: 358b521

If that makes sense to you, I'll close the issue.

This is interesting! When you only create Coupling6, the returned value is 2. However, when you create Coupling6 plus Box the returned value is 1.

Yeah, that's what happens when you are creating 'fake' examples. If there are things that can't really be resolved, I try to approximate.

There was a bug in inexistent generic classes. Hopefully, I just fixed it: a69e34f

Wrote more tests, it seems to work, @aaghamohammadi

2b63d1b

This is strange. Really strange!

Consider the following code:

public class Coupling61 {
	private Box2<Integer> integerBox = new Box2<Integer>();
}

public class Coupling62 {
	private Box2<A> integerBox = new Box2<A>();
}

public class Coupling63 {
	private Box<A> integerBox = new Box<A>();
} 

CBO is correct (1,2 ,2).

However, for the following code:

public class Coupling61 {
	private Box<Integer> integerBox = new Box<Integer>();
}

public class Coupling62 {
	private Box2<Integer> integerBox = new Box2<Integer>();
}

public class Coupling63 {
	private Box<A> integerBox = new Box<A>();
}

CBO is incorrect (expected:1,1,2 --- output:1,1,1) .

Your Coupling63 example is the same in both snippets. I tried one more combination there, and it works.

Can you write a failing test?

Yes. I have written a test that fails. I sent a pull request which includes that test.