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

DM Smith (JIRA) jira at crosswire.org
Sat Mar 12 14:36:26 MST 2011


    [ http://www.crosswire.org/bugs/browse/JS-177?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14116#comment-14116 ] 

DM Smith commented on JS-177:
-----------------------------

Just checked in a change. It no longer throws an NPE but now throws a BookException.

> 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