Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException for duplicate dependencies #61

Open
StephanPraetsch opened this issue Jun 18, 2020 · 4 comments
Open

ArrayIndexOutOfBoundsException for duplicate dependencies #61

StephanPraetsch opened this issue Jun 18, 2020 · 4 comments

Comments

@StephanPraetsch
Copy link
Contributor

StephanPraetsch commented Jun 18, 2020

Hi,

when I add a dependency twice, like

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
            <version>1.11.61</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
            <version>1.11.61</version>
            <scope>test</scope>
            <type>test-jar</type>
        </dependency>

and then I exclude something in the first dependency, like jmespath-java
deps

then krasa.mavenhelper.analyzer.action.ExcludeDependencyAction#exclude calls dependencyExcluded() twice and the second call produces this exception

2020-06-18 12:23:06,687 [ 907067]  ERROR - llij.ide.plugins.PluginManager - 1 
java.lang.ArrayIndexOutOfBoundsException: 1
	at krasa.mavenhelper.analyzer.action.LeftTreePopupHandler$2.dependencyExcluded(LeftTreePopupHandler.java:79)
	at krasa.mavenhelper.analyzer.action.ExcludeDependencyAction.exclude(ExcludeDependencyAction.java:62)
	at krasa.mavenhelper.analyzer.action.ExcludeDependencyAction.access$000(ExcludeDependencyAction.java:25)
	at krasa.mavenhelper.analyzer.action.ExcludeDependencyAction$2$1.run(ExcludeDependencyAction.java:91)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:976)
	at krasa.mavenhelper.analyzer.action.ExcludeDependencyAction$2.run(ExcludeDependencyAction.java:89)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:220)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:178)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:168)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:154)
	at krasa.mavenhelper.analyzer.action.ExcludeDependencyAction.actionPerformed(ExcludeDependencyAction.java:87)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:280)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.lambda$actionPerformed$0(ActionMenuItem.java:296)
	at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:281)
	at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:77)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:285)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$fireActionPerformed$0(ActionMenuItem.java:112)
	at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:112)
	at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:517)
	at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:36)
	at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:539)
	at java.awt.Component.processMouseEvent(Component.java:6533)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
	at java.awt.Component.processEvent(Component.java:6298)
	at java.awt.Container.processEvent(Container.java:2236)
	at java.awt.Component.dispatchEventImpl(Component.java:4889)
	at java.awt.Container.dispatchEventImpl(Container.java:2294)
	at java.awt.Component.dispatchEvent(Component.java:4711)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
	at java.awt.Container.dispatchEventImpl(Container.java:2280)
	at java.awt.Window.dispatchEventImpl(Window.java:2746)
	at java.awt.Component.dispatchEvent(Component.java:4711)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
	at java.awt.EventQueue$4.run(EventQueue.java:731)
	at java.awt.EventQueue$4.run(EventQueue.java:729)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:974)
	at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.java:912)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:844)
	at com.intellij.ide.IdeEventQueue.lambda$null$8(IdeEventQueue.java:449)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:741)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:448)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:502)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
2020-06-18 12:23:06,687 [ 907067]  ERROR - llij.ide.plugins.PluginManager - IntelliJ IDEA 2020.1.2  Build #IU-201.7846.76 
2020-06-18 12:23:06,688 [ 907068]  ERROR - llij.ide.plugins.PluginManager - JDK: 1.8.0_144; VM: Java HotSpot(TM) 64-Bit Server VM; Vendor: Oracle Corporation 
2020-06-18 12:23:06,688 [ 907068]  ERROR - llij.ide.plugins.PluginManager - OS: Linux 
2020-06-18 12:23:06,688 [ 907068]  ERROR - llij.ide.plugins.PluginManager - Plugin to blame: Maven Helper version: 4.9.193.000.0 

My simple approach was to move dependencyExcluded() out of the for-loop to just after it

	for (MavenDomDependency mavenDomDependency : dependencies.getDependencies()) {
            [...]
	}
	if (found) {
	    dependencyExcluded();
	}

This kind of works for the pom.xml in text mode

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
            <version>1.11.61</version>
            <exclusions>
                <exclusion>
                    <artifactId>jmespath-java</artifactId>
                    <groupId>com.amazonaws</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
            <version>1.11.61</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>jmespath-java</artifactId>
                    <groupId>com.amazonaws</groupId>
                </exclusion>
            </exclusions>
            <type>test-jar</type>
        </dependency>

but the UI is refreshed and displays jmespath-java still for the second dep
after

After hitting "Refresh UI" it even displays jmespath-java for the first dep as well (see first screenshot).

I need to "Reimport" and then it's fine.

I didn't make a pull request because I'm not sure whether my change would be appropriate because of the UI bugs afterwards.

@krasa
Copy link
Owner

krasa commented Jun 18, 2020

After hitting "Refresh UI" it even displays jmespath-java for the first dep as well (see first screenshot).

I need to "Reimport" and then it's fine.

That is fine. IntelliJ holds the model; it is updated by Reimport. Removing nodes from the GUI is only for UX.

Maybe it would be better to exclude it only from the right node: 443534d

@StephanPraetsch
Copy link
Contributor Author

StephanPraetsch commented Jun 19, 2020

Ah ok. Haven't looked at Intellij's maven structure. If those "UI bugs" are due to Intellij's not-updated model of that pom.xml then why is my approach not enough? My approach seems reasonable because it's near the exception and fixes that exception. I don't understand how your referenced commit should fix the bug. It doesn't, btw.

@krasa
Copy link
Owner

krasa commented Jun 19, 2020

It seems wrong to exclude it from 2 places and then remove it from the GUI only on one.

The solution should not be to simply get rid of the exception (your fix), or to remove it in the GUI on two places, but to exclude it only from the right dependency (my fix).
I tried to fix it by matching more attributes to get rid of the false positive from #isSameDependency - yes, it does not work for your case, it did for mine :(.

Now I fixed it a bit more, but now I am worried about false negatives. Maybe it will be better to do the filtering in several steps until only one pom dependency matches.
https://github.com/krasa/MavenHelper/compare/isSameDependency

@StephanPraetsch
Copy link
Contributor Author

StephanPraetsch commented Jun 19, 2020

Ah, I see.

I'd love to add some integration-tests but still failing :( That would help a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants