#12 bug in ComparisonFailure

Latest_release
open
nobody
5
2004-08-05
2004-08-05
No

bug at line 145 of ComparisonFailure, when the actual
is shorter than the expected and the difference is at
the end of the actual (StringIndexOutOfBoundsException)

Discussion

  • Logged In: NO

    Here's a test case to illustrate the bug: paste into
    ComparisonFailureTest.suite().

    suite.addTest(new
    ComparisonFailureTest("ExpectedLongerThenActual", null,
    expected, expected.substring(0, 20),
    "expected:<1234567890...> but was:<aaaa567890...> ['aaaa']"));

    The result is an error:

    java.lang.StringIndexOutOfBoundsException: String index out
    of range: 20
    at java.lang.String.charAt(String.java:444)
    at
    junitx.framework.ComparisonFailure.createMessage(ComparisonFailure.java:145)
    at
    junitx.framework.ComparisonFailureTest.execute(ComparisonFailureTest.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at junitx.framework.TestSuite.runTest(TestSuite.java:176)
    at junitx.framework.TestSuite.run(TestSuite.java:171)
    at
    com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at
    com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)