NEW DATE! Bugzilla will undergo maintenance 2024-03-28 18h00 CET. Bugzilla will be placed in read-only mode at that time.

Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 21370 - WordPatternRule freezes editor
Summary: WordPatternRule freezes editor
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 major (vote)
Target Milestone: 2.0.1   Edit
Assignee: Kai-Uwe Maetzel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-08 14:01 EDT by Frans Blezer CLA
Modified: 2002-08-23 13:00 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frans Blezer CLA 2002-07-08 14:01:34 EDT
I've added the following word pattern rule to the JavaPartitionScanner class of 
the java editor example:

rules.add(new WordPatternRule(new JavaWordDetector(), "ice", "cube", comment));

The JavaWordDetector is imported from the 
org.eclipse.ui.examples.javaeditor.util package (incidentally there is another 
JavaWordDetector in the org.eclipse.ui.examples.javaeditor.java package which 
seems never to be used in the example).

I then run the modified example, create a new *.jav file and start typing the 
text 'icecube'. The editor freezes after I've typed 'ic'.

Similarly when I open a *.jav file that contains this text, it is colored 
correctly like a comment, but when I try to edit it the editor freezes again.

The console of the development environment shows the following error message:

Unhandled exception caught in event loop.
Reason:
java.lang.ArrayIndexOutOfBoundsException

I've tried this both with j2sdk versions 1.4.0 and 1.4.1beta.
Comment 1 Frans Blezer CLA 2002-07-12 04:10:51 EDT
I've looked at the sources of the WordPatternRule and the PatternRule in the 
org.eclipse.jface.text.rules package and found the problem.

The PatternRule's doEvaluate method reads a character from the scanner and 
determines whether it is part of the start sequence. If it is part of the start 
sequence it tries to detect the rest of that sequence and, if that is found, it 
looks for the end sequence using the endSequenceDetected method.

If either of these sequences is not found it unreads the character from the 
scanner returns a Token.UNDEFINED.

The WordPatternRule overrides the endSequenceDetected method. If the end 
sequence is not detected this method unreads the entire buffer including the 
startsequence in the unreadBuffer method.

But on return in the PatternRule.doEvaluate method another scanner.unread() 
call is made, therefor unreading past the beginning of the start sequence.

To fix this the for loop in the WordPattern.unreadBuffer method should be 
changed from:

for (int i= fBuffer.length() - 1; i >= 0; i--)

to:

for (int i= fBuffer.length() - 1; i > 0; i--)

so that it leaves the last character in the buffer alone for the PatternRule to 
unread.


Comment 2 Frans Blezer CLA 2002-07-12 04:30:33 EDT
Nick,

I had originally entered this call on the wrong component. I've corrected this 
and I've taken the liberty of reassigning it to you as the owner of this 
component.

Frans
Comment 3 Nick Edgar CLA 2002-07-12 11:22:38 EDT
I've removed the unused JavaWordDetector in 
org.eclipse.ui.examples.javaeditor.java.

Reassigning to Kai to look at the hang problem.
Comment 4 Kai-Uwe Maetzel CLA 2002-08-12 06:27:02 EDT
Proposed change released into the 2.0.1 and the 2.1 stream.