History | Log In     View a printable version of the current page. Get help!  
Issue Details (XML | Word)

Key: WT-356
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Assignee: Marc Guillemot
Reporter: Florent Blondeau
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
WebTest

AbstractSelectStep.doMatch(String,String) failed when the second parameter is null

Created: 28/Nov/07 14:19:25   Updated: 28/Nov/07 17:05:06
Affects Version/s: 2.5
Fix Version/s: 2.6

Environment: tested on Java JDK 1.6.0_02 / Debian 4.2.2-3 on Linux Kernel 2.6.23 with Groovy 1.0.0
should behave the same way on other platforms


 Description   
If getSubject() returns null on a Message (I encountered that on an IMAP box),
doMatch(getSubject(), message.getSubject()) called in AbstractSelectStep.messageMatches fails with a NullPointerException with stack trace like :
java.lang.NullPointerException
at java.util.regex.Matcher.getTextLength(Matcher.java:1140)
at java.util.regex.Matcher.reset(Matcher.java:291)
at java.util.regex.Matcher.<init>(Matcher.java:211)
at java.util.regex.Pattern.matcher(Pattern.java:888)
at com.canoo.webtest.engine.RegExStringVerifier.verifyStrings(RegExStringVerifier.java:28)
at com.canoo.webtest.plugins.emailtest.AbstractSelectStep.doMatch(AbstractSelectStep.java:149)
at com.canoo.webtest.plugins.emailtest.AbstractSelectStep.messageMatches(AbstractSelectStep.java:128)

The code tests if the expected String is null, but not if the actual String is null. Code could be fix like below :

    static boolean doMatch(final String expected, final String actual) {
        // semantics are: if no expectation then match
        if (StringUtils.isEmpty(expected)) {
            return true;
        }
/* new part */
        //semantics are: if no actual string then no match
        if (StringUtils.isEmpty(actual)){
         return false;
        }
/* end of new part */
        if (isRegexMatch(expected)) {
            return getVerifier(true).verifyStrings(expected.substring(1, expected.length() - 1), actual);
        }
        return getVerifier(false).verifyStrings(expected, actual);
    }

 All   Comments   Change History      Sort Order:
Comment by Florent Blondeau [28/Nov/07 14:29:33]
Actually, before fixing like above, we should ask ourselves how the cases where both strings are either null or "" should be handled
This will determine the tests to perform, and the order in which they have to be done

Comment by Marc Guillemot [28/Nov/07 17:05:06]
Fixed in build 1642.

I've decided to handle null like empty string as it is not clear when Message instance returns null.