[jsword-devel] [JIRA] Created: (JS-177) Need a null check in GenBookBackend.getRawText

Martin Denham (JIRA) jira at crosswire.org
Sat Mar 12 07:59:24 MST 2011


Need a null check in GenBookBackend.getRawText
----------------------------------------------

                 Key: JS-177
                 URL: http://www.crosswire.org/bugs/browse/JS-177
             Project: JSword
          Issue Type: Bug
          Components: o.c.jsword.book.sword
    Affects Versions: 1.6.1
         Environment: All
            Reporter: Martin Denham
            Assignee: DM Smith


A null check is required in the following code in GenBookBackend.getRawText because find can return a null meaning that node, when used on the next line could be null:

            DataPolice.setKey(key);
            TreeNode node = find(key);
            byte[] userData = node.getUserData();

            // Some entries may be empty.
            if (userData.length == 8) {

Here is a suggested fix but I don't know if you should return a null or an empty string in this scenario:

            DataPolice.setKey(key);
            TreeNode node = find(key);
            
            // Is there an entry?
            if (node == null) {
                return "";
            }

            byte[] userData = node.getUserData();

Here is a simple test:
	Book book = getBook("Pilgrim");
	Key key = book.getGlobalKeyList();
	String rawText = book.getRawText(key);


--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira



More information about the jsword-devel mailing list