This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 209401 - DefaultKeyTypedAction#replaceSelection is against assumption called with empty string as argument
Summary: DefaultKeyTypedAction#replaceSelection is against assumption called with empt...
Status: VERIFIED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: CSL (API & infrastructure) (show other bugs)
Version: 7.2
Hardware: PC All
: P2 normal (vote)
Assignee: Milutin Kristofic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-10 01:38 UTC by sfj39
Modified: 2014-01-08 11:51 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
potential patch (3.04 KB, patch)
2014-01-03 19:35 UTC, matthias42
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description sfj39 2012-03-10 01:38:22 UTC
Using the developer 7.2 build of NetBeans and the Python plugin:

java.lang.StringIndexOutOfBoundsException: String index out of range: 0

Basically, *every time* you highlight a variable name, module name, function name, etc... and try to type over it and replace it with a new name, it generates this exception.

You can 'work around it' by closing the exception window and then hitting backspace and then typing (or remembering to do that in the first place) your variable name, but it's a *severely* annoying issue that applies everywhere (Python Code, C/C++ code, etc...).

Deactivating the Python plugins removes this problem.

There's a list of other people who have the same problems, and they are all at:
http://statistics.netbeans.org/analytics/exception.do?id=562918
Comment 1 sfj39 2012-03-10 01:39:29 UTC
Sorry, wrong project group.
Comment 2 sfj39 2012-03-10 01:47:02 UTC
Also affects Mac OS X, Windows 7 (from the statistics.netbeans.org site)
Comment 3 matthias42 2014-01-03 19:35:53 UTC
Created attachment 143585 [details]
potential patch

Ok - first it is reproducible:

1. Write this to a file and name it test.py

#! /usr/bin/python
# -*- coding: utf8 -*-
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
config = {
}

2. Make sure you have the python plugins installed
3. Open the file above
4. Mark the work config by double clicking on it
5. Enter a character via the keyboard

Expected result:

Marked word (config) is removed from document and pressed character is inserted.

Result instead:

No visible reaction apart from a hidden exception:

java.lang.StringIndexOutOfBoundsException: String index out of range: 0
	at java.lang.String.charAt(String.java:658)
	at org.netbeans.modules.gsf.GsfEditorKitFactory$GsfEditorKit$GsfDefaultKeyTypedAction.replaceSelection(GsfEditorKitFactory.java:299)
	at org.netbeans.editor.BaseKit$DefaultKeyTypedAction$2.run(BaseKit.java:1140)
	at org.netbeans.editor.GuardedDocument.runAtomicAsUser(GuardedDocument.java:351)
	at org.netbeans.editor.BaseKit$DefaultKeyTypedAction.actionPerformed(BaseKit.java:1131)
	at org.netbeans.editor.ext.ExtKit$ExtDefaultKeyTypedAction.actionPerformed(ExtKit.java:1024)
	at org.netbeans.modules.gsf.GsfEditorKitFactory$GsfEditorKit$GsfDefaultKeyTypedAction.actionPerformed(GsfEditorKitFactory.java:267)
	at org.netbeans.editor.BaseAction.actionPerformed(BaseAction.java:339)
	at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1661)
	at javax.swing.JComponent.processKeyBinding(JComponent.java:2870)
	at javax.swing.JComponent.processKeyBindings(JComponent.java:2917)
	at javax.swing.JComponent.processKeyEvent(JComponent.java:2833)
	at java.awt.Component.processEvent(Component.java:6282)
	at java.awt.Container.processEvent(Container.java:2229)
	at java.awt.Component.dispatchEventImpl(Component.java:4861)
	at java.awt.Container.dispatchEventImpl(Container.java:2287)
	at java.awt.Component.dispatchEvent(Component.java:4687)
	at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1895)
	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:762)
	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1027)
	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:899)
	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:727)
	at java.awt.Component.dispatchEventImpl(Component.java:4731)
	at java.awt.Container.dispatchEventImpl(Container.java:2287)
	at java.awt.Window.dispatchEventImpl(Window.java:2719)
	at java.awt.Component.dispatchEvent(Component.java:4687)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
	at java.awt.EventQueue.access$200(EventQueue.java:103)
	at java.awt.EventQueue$3.run(EventQueue.java:694)
	at java.awt.EventQueue$3.run(EventQueue.java:692)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
	at java.awt.EventQueue$4.run(EventQueue.java:708)
	at java.awt.EventQueue$4.run(EventQueue.java:706)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
	at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
[catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)


The error lies in the expectation, that replaceSelection always receives a string with a least one character (so far so sane). But replaceSelection is no called from BaseKit.java line 1140 with an empty string a replacement string. This was introduced (or at least last touched) by:

213877:e9a6ebb16ec5 - mkristofic 27.02.2012
#204450 - Rewrite actions to use TypingHooks SPI

With the empty string the hole thing blows in GsfEditorKitFactory.java line 299 (str.charAt(0) will fail then).

My guess: every language based on GSF is broken by this bug. Based on this analysis I'll reassign, the the problem is not in the python support code (either the GsfEditorKitFactory or BaseKit need to be fixed). Attached is a potential fix for the concrete problem.
Comment 4 Milutin Kristofic 2014-01-05 14:27:37 UTC
You are right, my change didn't count with gsf implementation and I had same bug in csl, which I fixed in #208931.

I don't maintain gsf, but I don't see reasonable fix in Basekit since I need empty replace for new TypingHooks API to work. 

I will ask in Monday, if I can push to gsf, and I will fix gsf similarly as you suggest.
Comment 5 Milutin Kristofic 2014-01-06 12:12:05 UTC
Mathias, you can commit and push your patch to contrib/gsf by yourself. Gsf is not maintaining anymore and python should be last language implented in gsf. It would be best to rewrite python from gsf to csl, otherwise python maintainer must to maintain gsf as well. 

If you don't have rights to contrib, I can do it.
Comment 6 matthias42 2014-01-06 12:27:26 UTC
Hey Milutin, thanks for checking - I don't have mercurial access, so I would like to ask you to push the change. For the maintaining of python - is there a maintainer? I'll have a look at the structure and see how much work it would be to just do a straight port to CSL - no promises though.
Comment 7 Milutin Kristofic 2014-01-07 14:50:53 UTC
I pushed your change Matthias. http://hg.netbeans.org/main/contrib/rev/b3b011ed82ed 

Thank you for help.
Comment 8 matthias42 2014-01-08 11:51:32 UTC
Thank you Milutin, the push made it already into the builds and fixed the problem!