Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 344745

Summary: [search] ArrayIndexOutOfBoundsException in DiskIndex during problem detection
Product: [WebTools] JSDT Reporter: Patric Rufflar <patric>
Component: GeneralAssignee: Project Inbox <jsdt.javascript-inbox>
Status: RESOLVED WORKSFORME QA Contact: Chris Jaun <cmjaun>
Severity: normal    
Priority: P3 CC: cmjaun, earlyster, Michael_Rennie, vrubezhny
Version: unspecified   
Target Milestone: 3.5.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
file which will reproduce the bug
none
The patch fixes the issue none

Description Patric Rufflar CLA 2011-05-04 13:41:56 EDT
Build Identifier: 3.2.3

java.lang.ArrayIndexOutOfBoundsException: 0
	at org.eclipse.wst.jsdt.internal.core.index.DiskIndex.addQueryResults(DiskIndex.java:200)
	at org.eclipse.wst.jsdt.internal.core.index.Index.query(Index.java:147)
	at org.eclipse.wst.jsdt.internal.core.search.matching.MethodPattern.queryIn(MethodPattern.java:338)
	at org.eclipse.wst.jsdt.internal.core.search.matching.InternalSearchPattern.findIndexMatches(InternalSearchPattern.java:92)
	at org.eclipse.wst.jsdt.internal.core.search.matching.OrPattern.findIndexMatches(OrPattern.java:68)
	at org.eclipse.wst.jsdt.internal.core.search.matching.MatchLocator.findIndexMatches(MatchLocator.java:396)
	at org.eclipse.wst.jsdt.internal.core.search.PatternSearchJob.search(PatternSearchJob.java:116)
	at org.eclipse.wst.jsdt.internal.core.search.PatternSearchJob.execute(PatternSearchJob.java:66)
	at org.eclipse.wst.jsdt.internal.core.search.processing.JobManager.performConcurrentJob(JobManager.java:280)
	at org.eclipse.wst.jsdt.internal.core.search.BasicSearchEngine.searchAllBindingNames(BasicSearchEngine.java:732)
	at org.eclipse.wst.jsdt.internal.core.NameLookup.findBindingSearch(NameLookup.java:2184)
	at org.eclipse.wst.jsdt.internal.core.NameLookup.findBinding(NameLookup.java:836)
	at org.eclipse.wst.jsdt.internal.core.SearchableEnvironment.findBinding(SearchableEnvironment.java:200)
	at org.eclipse.wst.jsdt.internal.core.SearchableEnvironment.findBinding(SearchableEnvironment.java:379)
	at org.eclipse.wst.jsdt.internal.core.CancelableNameEnvironment.findBinding(CancelableNameEnvironment.java:55)
	at org.eclipse.wst.jsdt.internal.compiler.lookup.LookupEnvironment.askForBinding(LookupEnvironment.java:191)
	at org.eclipse.wst.jsdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:249)
	at org.eclipse.wst.jsdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:2115)
	at org.eclipse.wst.jsdt.internal.compiler.lookup.Scope.getBinding(Scope.java:1087)
	at org.eclipse.wst.jsdt.internal.compiler.ast.SingleNameReference.findBinding(SingleNameReference.java:478)
	at org.eclipse.wst.jsdt.internal.compiler.ast.SingleNameReference.resolveType(SingleNameReference.java:369)
	at org.eclipse.wst.jsdt.internal.compiler.ast.SingleNameReference.resolveType(SingleNameReference.java:361)
	at org.eclipse.wst.jsdt.internal.compiler.ast.Expression.resolve(Expression.java:477)
	at org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:394)
	at org.eclipse.wst.jsdt.internal.compiler.Compiler.resolve(Compiler.java:645)
	at org.eclipse.wst.jsdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:258)
	at org.eclipse.wst.jsdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:247)
	at org.eclipse.wst.jsdt.internal.core.Openable.generateInfos(Openable.java:241)
	at org.eclipse.wst.jsdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:538)
	at org.eclipse.wst.jsdt.internal.core.CompilationUnit.makeConsistent(CompilationUnit.java:1034)
	at org.eclipse.wst.jsdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:177)
	at org.eclipse.wst.jsdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:96)
	at org.eclipse.wst.jsdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:742)
	at org.eclipse.wst.jsdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:802)
	at org.eclipse.wst.jsdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1183)
	at org.eclipse.wst.jsdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1160)
	at org.eclipse.wst.jsdt.web.core.javascript.JsTranslation.reconcileCompilationUnit(JsTranslation.java:540)
	at org.eclipse.wst.jsdt.web.core.internal.validation.JsValidator.performValidation(JsValidator.java:176)
	at org.eclipse.wst.jsdt.web.core.internal.validation.JsValidator.validateFile(JsValidator.java:336)
	at org.eclipse.wst.jsdt.web.core.internal.validation.JsValidator.validate(JsValidator.java:246)
	at org.eclipse.wst.sse.ui.internal.reconcile.validator.ReconcileStepForValidator.validate(ReconcileStepForValidator.java:292)
	at org.eclipse.wst.sse.ui.internal.reconcile.validator.ReconcileStepForValidator.reconcileModel(ReconcileStepForValidator.java:258)
	at org.eclipse.jface.text.reconciler.AbstractReconcileStep.reconcile(AbstractReconcileStep.java:95)
	at org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy.reconcile(ValidatorStrategy.java:264)
	at org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor.process(DocumentRegionProcessor.java:303)
	at org.eclipse.wst.sse.ui.internal.reconcile.StructuredRegionProcessor.process(StructuredRegionProcessor.java:221)
	at org.eclipse.wst.sse.ui.internal.reconcile.DirtyRegionProcessor.run(DirtyRegionProcessor.java:667)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)


Reproducible: Always

Steps to Reproduce:
1. Open attached file
Comment 1 Patric Rufflar CLA 2011-05-04 13:42:52 EDT
Created attachment 194748 [details]
file which will reproduce the bug

open the file.
Comment 2 Victor Rubezhny CLA 2012-05-05 10:52:49 EDT
Created attachment 215127 [details]
The patch fixes the issue

For some reason (maybe as result of syntax errors or mixing a JSP,PHP and JS code in the example file) there is possible to achieve an empty name for a token which will be passed as a key parameter of org.eclipse.wst.jsdt.internal.core.index.DiskIndex.addQueryResults(char[][], char[], int, MemoryIndex) method from a MethodPattern search pattern. 
The addQueryIndex(...) method has a handling for a null-key, but never checks that the key may be an empty array of characters. So, I've added a check for (key.length == 0) which is made the addQueryResults(...) method to act exactly as the null-key is passed to the method (it caches all the words for all the categories into a search result instead of trying to compare an empty key with a word from a category).
Comment 3 Justin Early CLA 2013-01-29 12:03:21 EST
Per this thread [1] vjet team was asked to look at this bug to see if it also applies to vjet.

This bug doesn't apply to VJET currently. There is currently wired off support for JS authoring inside HTML files / JSP files / PHP files. There is currently a request to add JS authoring support for HTML/JSP/PHP files 395973 and 398937. 

[1] http://dev.eclipse.org/mhonarc/lists/vjet-dev/msg00022.html
Comment 4 Chris Jaun CLA 2013-08-30 16:56:52 EDT
I can't reproduce this issue in the 8/29 WTP 3.5.1 driver even before applying the patch.

If this is still an issue, please re-open.