apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.69k stars 853 forks source link

Generate [Insert ctrl+i] Dependency does not insert chosen dependency #7924

Open cbm64chris opened 1 month ago

cbm64chris commented 1 month ago

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.

<plugin>
        <groupId>com.github.ekryd.sortpom</groupId>
        <artifactId>sortpom-maven-plugin</artifactId>
        <version>4.0.0</version>
        <configuration>
          <createBackupFile>false</createBackupFile>
          <encoding>UTF-8</encoding>
          <expandEmptyElements>false</expandEmptyElements>
          <spaceBeforeCloseEmptyElement>false</spaceBeforeCloseEmptyElement>
          <sortDependencies>scope,groupId,artifactId</sortDependencies>
          <sortPlugins>groupId,artifactId</sortPlugins>
          <nrOfIndentSpace>4</nrOfIndentSpace>
          <keepBlankLines>true</keepBlankLines>
        </configuration>
      </plugin>

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

cbm64chris commented 1 month ago

That is annoying - I just cold started NetBeans to record my screen and it worked !***!

I will attach a recording when it happens again.