<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Apr 1, 2009, at 10:55 PM, Yiguang Hu wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>I created a Chinese dictionary using imp2ld.exe. It works fine if the key is in English. But If use Chinese as Key the search would fail with the following exception. Any idea?<br><br>Thanks<br>Yiguang<br><br>Caused by: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: -1<br> at org.crosswire.jsword.book.sword.RawLDBackend.get(RawLDBackend.java:162)<br> at org.crosswire.jsword.book.sword.SwordDictionary.getKey(SwordDictionary.java:176)<br> at GbookController.getBookKey(GbookController.groovy:987)<br> at GbookController.this$2$getBookKey(GbookController.groovy)<br> at GbookController.getBookData(GbookController.groovy:955)<br> at GbookController.this$2$getBookData(GbookController.groovy)<br> at GbookController.getOSISProvider(GbookController.groovy:933)<br> at GbookController.this$2$getOSISProvider(GbookController.groovy)<br> at GbookController.getOSISString(GbookController.groovy:762)<br> at GbookController$_closure12.doCall(GbookController.groovy:481)<br> at GbookController$_closure12.doCall(GbookController.groovy)<br></div></blockquote></div><div><br></div>The routine that is calling RawLDBackend.get(int) is passing a -1.<div><br></div><div>Here is the SwordDictionary.getKey(text) method):</div><div><br><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #7f0055">public</span> Key getKey(String text) <span style="color: #7f0055">throws</span> NoSuchKeyException</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> checkActive();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #7f0055">int</span> pos = <span style="color: #0000c0">backend</span>.indexOf(<span style="color: #7f0055">new</span> DefaultLeafKeyList(text));</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #7f0055">if</span> (pos < 0)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #7f0055">if</span> (<span style="color: #0000c0">backend</span>.getCardinality() > -pos - 1)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #7f0055">return</span> <span style="color: #0000c0">backend</span>.get(-pos - 1);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> }</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #7f0055">return</span> <span style="color: #0000c0">backend</span>.get(<span style="color: #0000c0">backend</span>.getCardinality() - 1);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> }</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #7f0055">return</span> <span style="color: #0000c0">backend</span>.get(pos);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> }</div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;">From this it appears that pos is getting a negative value and is hitting the line:</span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;">return backend.get(backend.getCardinality() - 1);</span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;">The purpose of this is on a full miss to return the last element in the dictionary.</span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;">Since the exception is reporting an array out of bounds exception of -1, it appears that</span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;">backend.getCardinality()</span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;">is returning 0.</span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;">The computation of getCardinality() first opens the module with a call to checkActive(). There's a bit of magic going on here with activator, but that calls activate(). If activate() encounters a problem with opening any of the files, it returns that the module has 0 entries. If it encounters any problem, it reports the problem via the Reporter (Have you set up a listener to the Reporter?) or the log (have you checked the log?). </span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;">Otherwise, it gets the size of the index file and divides that by size of a single entry in the index, as every entry in the index is the same size.</span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;">My suggestion is to check the size of the idx and dat files to see if they make sense. If so, check the read permissions on them and the folders above them. If that checks out, debug line 195 in RawLDBackend to see if the path makes sense. If it does not, check the conf to see if it specifies DataPath properly.</span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;">Hope this helps.</span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;">In Christ,</span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><span class="Apple-tab-span" style="white-space:pre">        </span>DM<br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div></div></div></body></html>