| Summary: | [search] JavaElementLine crashes with ArrayIndexOutOfBoundsException when there is EOF encountered | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Andrew Eisenberg <andrew.eisenberg> |
| Component: | UI | Assignee: | Markus Keller <markus.kell.r> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | juan_r958, markus.kell.r |
| Version: | 3.6.2 | ||
| Target Milestone: | 3.7 M7 | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
Fixed in HEAD of JavaElementLine (was not as simple as suggested in comment 0 ;-). Thanks for fixing so fast. *** Bug 341717 has been marked as a duplicate of this bug. *** |
The constructor org.eclipse.jdt.internal.ui.search.JavaElementLine.JavaElementLine(ITypeRoot, int, int) expects that the end of the line ends with a \n or a \r char. However, there are situations where an EOF is reached with no \r or \n. The only time I have encountered this in Java code is with a syntax error. See this class: class Foo { int x Now, select the x field and do CTRL-Shift-U. And the result is an exception in the log: eclipse.buildId=M20110210-1200 java.version=1.6.0_22 java.vendor=Apple Inc. BootLoader constants: OS=macosx, ARCH=x86, WS=cocoa, NL=en_US Framework arguments: -product com.springsource.sts.ide Command-line arguments: -os macosx -ws cocoa -arch x86 -product com.springsource.sts.ide -data /users/Andrew/Eclipse/Workspaces/workspaceAJDT36 Error Thu Mar 10 14:42:35 PST 2011 An internal error occurred during: "Search for Occurrences in File". java.lang.ArrayIndexOutOfBoundsException at org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter.getChar(DocumentAdapter.java:369) at org.eclipse.jdt.internal.ui.search.JavaElementLine.<init>(JavaElementLine.java:70) at org.eclipse.jdt.internal.ui.search.OccurrencesSearchQuery.getLineElement(OccurrencesSearchQuery.java:113) at org.eclipse.jdt.internal.ui.search.OccurrencesSearchQuery.run(OccurrencesSearchQuery.java:79) at org.eclipse.search2.internal.ui.InternalSearchUI$InternalSearchJob.run(InternalSearchUI.java:91) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54) The fix is simple. In the condition for the while loop on line 64, add a check for EOF: while (i < length && !IndentManipulation.isLineDelimiterChar(ch) && !IndentManipulation.isEOFChar(ch)) {