Export to GitHub

testability-explorer - issue #2

MethodInfo#canOverride() misses the case when the method is final


Posted on Oct 8, 2008 by Swift Cat

What is the expected output? What do you see instead?

I expect the final method to be marked as NOT overridable.

Failing Test:

public void testMediumFinalCost2() throws Exception { MethodInfo method = repo.getClass(Medium.class.getName()).getMethod("finalCost2()I"); assertFalse(method.canOverride()); MethodCost cost = computer.compute(Medium.class.getName(), "finalCost2()I"); assertEquals(3l, cost.getTotalComplexityCost()); }

  • Method necessary to add to the class Medium (static class inside MetricComputerTest)

CODE:

/** * I cost 2, but I am a <em>final</em> instance method that can not be overridden. * My cost is unavoidable. */ public final int finalCost2() { int i = 0; return i > 0 ? i > 1 ? 1 : 2 : 2; }

Misko followed up on the mailing list with: QUOTE: Sounds like a real bug! Can you create a tests case and fix the bug? :-) If you can't fix it send me the test case and I will patch it in and submit a fix for you. -- Misko

http://groups.google.com/group/testability-explorer/browse_thread/thread/49b34c6ca1ad1209

Comment #1

Posted on Oct 9, 2008 by Swift Cat

fixed in revision 142.

Status: Verified

Labels:
Type-Defect Priority-Medium