Generate [Insert ctrl+i] Dependency does not insert chosen dependency
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### Apache NetBeans version
Apache NetBeans 23
### What happened
Using (macOS 14) opening a maven pom.xml in and positioning the cursor over the Dependency Management stanza; ctrl+I or Source->Insert->Dependency does not insert the chosen dependency. The dependency is not duplicate.
On cold start of NetBeans this action works fine - external actions to the IDE introduce this behaviour - see steps to reproduce.
Only trace in the IDE log I have seen after this event;
```
WARNING [org.netbeans.modules.options.keymap.LayersBridge]: Invalid shortcut: org.openide.loaders.XMLDataObject@1856ee2c[MultiFileObject@4b4ca015[Actions/Help/master-help.xml]]
INFO [org.netbeans.ui.indexing]: Indexing started, time from last indexing 1,584,970 ms.
INFO [org.netbeans.ui.indexing]: Indexing finished, indexing took 0 ms.
INFO [org.netbeans.ui.indexing]: Indexing started, time from last indexing 26,493 ms.
INFO [org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater]: Resolving dependencies took: 6 ms
INFO [org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater]: Complete indexing of 0 binary roots took: 0 ms
INFO [org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater]: Complete indexing of 0 source roots took: 0 ms (New or modified files: 0, Deleted files: 0) [Adding listeners took: 0 ms]
INFO [org.netbeans.ui.indexing]: Indexing finished, indexing took 13 ms.
INFO [org.netbeans.ui.indexing]: Indexing started, time from last indexing 851 ms.
INFO [org.netbeans.ui.indexing]: Indexing finished, indexing took 0 ms.
SEVERE [global]
java.lang.IllegalArgumentException: bad position: 35153
at java.desktop/javax.swing.text.JTextComponent.setCaretPosition(JTextComponent.java:1685)
at org.netbeans.modules.maven.codegen.AbstractGenerator.writeModel(AbstractGenerator.java:85)
at org.netbeans.modules.maven.codegen.DependencyGenerator.doInvoke(DependencyGenerator.java:91)
at org.netbeans.modules.maven.codegen.AbstractGenerator.invoke(AbstractGenerator.java:64)
at org.netbeans.modules.editor.codegen.GenerateCodePanel.invokeSelected(GenerateCodePanel.java:165)
at org.netbeans.modules.editor.codegen.GenerateCodePanel.listMouseReleased(GenerateCodePanel.java:109)
at org.netbeans.modules.editor.codegen.GenerateCodePanel.access$000(GenerateCodePanel.java:41)
at org.netbeans.modules.editor.codegen.GenerateCodePanel$2.mouseReleased(GenerateCodePanel.java:85)
at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:298)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6621)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3404)
at java.desktop/java.awt.Component.processEvent(Component.java:6386)
at java.desktop/java.awt.Container.processEvent(Container.java:2266)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4996)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:775)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:98)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:747)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:744)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:136)
[catch] at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
```
### Language / Project Type / NetBeans Component
Java Maven
### How to reproduce
Create a maven project with a dependency management section add any dependency. Add the sortpom plugin from com.github.ekryd.sortpom.
```XML
com.github.ekryd.sortpom
sortpom-maven-plugin
4.0.0
false
UTF-8
false
false
scope,groupId,artifactId
groupId,artifactId
4
true
```
Add a new dependency using the ctrl-i command to the dependency management section - does not matter what. That should work fine.
Now sort the pom using the sort-on:sort goal either from the command line or with the navigator.
Perform the same action to add a dependency to the pom, the IDE just skips to a _random_ position in the pom and no dependency is added.
I will add a gif of this behaviour shortly.
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
macOS Sonoma 14.7
### JDK
23 (arm64) "Oracle Corporation" - "Java SE 23"
### Apache NetBeans packaging
Apache NetBeans provided installer
### Anything else
_No response_
### Are you willing to submit a pull request?
No
Contributor guide
Research direction
Reproduce the issue with a Maven project and the sortpom plugin, then inspect org.netbeans.modules.maven.codegen.AbstractGenerator.writeModel and DependencyGenerator.doInvoke from the reported stack trace. Compare dependency insertion before and after running sort-on:sort; done means Ctrl+I or Source->Insert->Dependency inserts the chosen dependency at the correct position without the bad-position exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100