Bug 93432 - index out of bounds from indexing code
Summary: index out of bounds from indexing code
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC2   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 96424
Blocks:
  Show dependency tree
 
Reported: 2005-05-02 13:26 EDT by David Williams CLA
Modified: 2005-06-03 12:10 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Williams CLA 2005-05-02 13:26:08 EDT
using the 4/26 I build on M7 stream, I've noticed some code throws an IOOB's
exception while indexing a JSP file. The "root cause" may well be on our side
(we'll be investigating that, but wanted to call this to your attention, in case
it indicates some issue in base code that could be fixed for M7). It did not
occur in M6 base code. 

The excepition is thrown by following method in Index class. 
public String containerRelativePath(String documentPath) {
	int jarSeparator = documentPath.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
	return documentPath.substring((jarSeparator == -1 ? this.containerPath.length()
: jarSeparator) + 1);
}

Looking at this code, its obvious (since +1 always added) that if documentPath
length and containerPath length are equal, then an index out of bounds error will 
be thrown. Even if root cause is on our end, you might want to bullet proof your
code and if string are equal length, just use whole string. [Or, it might be the
+1 was intended only for jarSperator case? but I don't think so]. 

Thanks.
Comment 1 Kent Johnson CLA 2005-05-02 16:16:15 EDT
The documentPath is prefixed by the containerPath. For them to be equal, that 
would make the documentPath empty.

We do not put documents without names into the index.

We will detect this case & throw an IllegalArgumentException.
Comment 2 David Williams CLA 2005-05-02 17:15:02 EDT
Thanks, looks like we have the opposite problem, the 
containerPath and documentPath are equal as below. 
Obviously the containerPath is whole filename, in our 
case. Again, all I changed was base code, our code is the 
same, so ... even if our code is wrong, you might want to make 
your code more bullet proof. Just a suggestion. We'll continue to 
look at our code for improvement (and if we get a chance, we'll re-run 
the JSP Example that comes with base Eclipse ... since originally we 
were just following that. 

/org.eclipse.wst.sse.core.internal.encoding.newtests/__2F_org_2E_eclipse_2E_wst_2E_sse_2E_core_2E_internal_2E_encoding_2E_newtests_2F_testfiles_2F_regressionTestFiles_2F_defect224293_2F_testshiftjisXmlSyntax_2E_jsp.java
Comment 3 Kent Johnson CLA 2005-05-02 17:30:56 EDT
But the containerPath should be:

/org.eclipse.wst.sse.core.internal.encoding.newtests

Why is yours the full path?
Comment 4 David Williams CLA 2005-05-02 17:51:13 EDT
Not sure, we'll continue to investigate what's changed from M6 versions.
But thought it might help (obviously) if I included whole stack of what leads up 
to the IOOB exception. Our Search participant is involved, but first glance
doesn't seem to indicate it does much here (other than deleate to other java 
search function). Namely, at JSPSearchParticipant.indexDocument, this 
is the code that's executing:
SearchEngine.getDefaultSearchParticipant().indexDocument(document, indexPath);



======
Stack trace leading up to IOOB


Index.containerRelativePath(String) line: 82
JavaSearchDocumentDelegate(InternalSearchDocument).getContainerRelativePath()
line: 30
JavaSearchDocumentDelegate(InternalSearchDocument).removeAllIndexEntries() line: 38
JavaSearchDocumentDelegate(SearchDocument).removeAllIndexEntries() line: 128
JavaSearchParticipant.indexDocument(SearchDocument, IPath) line: 68
JSPSearchParticipant.indexDocument(SearchDocument, IPath) line: 73
IndexManager.indexDocument(SearchDocument, SearchParticipant, Index, IPath)
line: 289
IndexManager$1.execute(IProgressMonitor) line: 599
IndexManager(JobManager).run() line: 369
Comment 5 Kent Johnson CLA 2005-05-04 07:51:18 EDT
So what is the document path? And the indexPath?

We don't see a bug in our code. If you call:

SearchEngine.getDefaultSearchParticipant().indexDocument(document, indexPath);

with the document path == indexPath, then the bug is in your code.
Comment 6 Kent Johnson CLA 2005-05-06 12:49:32 EDT
Please reopen when you can show the bug is in our code.

We have released the changes to throw an IllegalArgumentException when the 
document path is the same as the container path.
Comment 7 David Williams CLA 2005-05-24 13:20:04 EDT
Reopening in light of bug 96424. 
We may need some clarification on how to handle "in memeory" documents. 
(That is, if this one is the bug, or if 96424 is the bug, or if we're doing
something wrong). 
Comment 8 Kent Johnson CLA 2005-05-26 10:53:30 EDT
Waiting on fix for bug 96424
Comment 9 Kent Johnson CLA 2005-06-03 12:10:40 EDT
David: please let us if the fix for 96424 does not do the trick.