Bug 216050 - [prov] SimplePlanner.sortOperations ArrayIndexOutOfBoundsException
Summary: [prov] SimplePlanner.sortOperations ArrayIndexOutOfBoundsException
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: p2 (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.4 M7   Edit
Assignee: Pascal Rapicault CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
: 226092 226543 226971 236595 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-01-21 15:54 EST by Simon Kaegi CLA
Modified: 2008-06-11 09:23 EDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Kaegi CLA 2008-01-21 15:54:25 EST
Using the AdminUI if I install an SDK into a profile and then try to install org.apache.commons.httpclient I'm getting the following stack trace:

java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.ArrayList.set(ArrayList.java:339)
	at org.eclipse.equinox.internal.p2.director.SimplePlanner.sortOperations(SimplePlanner.java:90)
	at org.eclipse.equinox.internal.p2.director.SimplePlanner.generateOperations(SimplePlanner.java:78)
	at org.eclipse.equinox.internal.p2.director.SimplePlanner.getInstallPlan(SimplePlanner.java:67)
	at org.eclipse.equinox.p2.ui.operations.ProvisioningUtil.getInstallPlan(ProvisioningUtil.java:171)
	at org.eclipse.equinox.p2.ui.actions.InstallAction.validateOperation(InstallAction.java:71)
	at org.eclipse.equinox.internal.p2.ui.actions.ProfileModificationAction$1.run(ProfileModificationAction.java:65)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)

To install the SDK I'm using a local metadata repo generated from 3.4M4.
To install org.apache.commons.httpclient I'm using an updatesite repo for test updates e.g. http://download.eclipse.org/eclipse/testUpdates/site.xml
Comment 1 Simon Kaegi CLA 2008-01-21 16:20:27 EST
Looking at the operands in "toSort" of SimplePlanner.sortOperations, I'm seeing:

1) install org.apache.commons.httpclient
2) uninstall org.eclipse.equinox.p2.core
3) uninstall org.eclipse.equinox.p2.metadata.generator

(1) looks right but (2) and (3) don't. The profile contains just the SDK and does not have either p2 bundles in it so I'm a bit baffled.
Comment 2 Pascal Rapicault CLA 2008-01-21 21:55:12 EST
I'll take ownership of that if you don't mind.
Comment 3 Simon Kaegi CLA 2008-01-21 23:11:02 EST
Great.
One thing to add is that the p2 bundles are getting brought in because the pde.build bundle on testUpdates has a dependency on the generator but doesn't in M4.

In other words, we're not just adding httpclient but also inadvertently updating at the same time. It's still a problem, it's just that there are more moving parts here than I had originally thought.
Comment 4 Pascal Rapicault CLA 2008-04-02 12:35:14 EDT
From bug 255340:
ARRAY INDEX OUT OF BOUNDS EXCEPTION
-----------------------------------
Next, I try to uninstall the Device Kit Core Feature because I would like to
try to installing both features at the same time, but the uninstall does not
work either.
!ENTRY org.eclipse.equinox.p2.ui 4 0 2008-04-01 14:29:57.031
!MESSAGE Unexpected error encountered while preparing for the operation.
!STACK 0
java.lang.ArrayIndexOutOfBoundsException: -1
        at java.util.ArrayList.set(Unknown Source)
        at
org.eclipse.equinox.internal.p2.director.SimplePlanner.sortOperations(SimplePlanner.java:122)
        at
org.eclipse.equinox.internal.p2.director.SimplePlanner.generateOperations(SimplePlanner.java:110)
        at
org.eclipse.equinox.internal.p2.director.SimplePlanner.generateProvisioningPlan(SimplePlanner.java:48)
        at
org.eclipse.equinox.internal.p2.director.SimplePlanner.getProvisioningPlan(SimplePlanner.java:367)
        at
org.eclipse.equinox.internal.provisional.p2.ui.operations.ProvisioningUtil.getProvisioningPlan(ProvisioningUtil.java:174)
        at
org.eclipse.equinox.internal.provisional.p2.ui.actions.UninstallAction.getProvisioningPlan(UninstallAction.java:82)
        at
org.eclipse.equinox.internal.provisional.p2.ui.actions.ProfileModificationAction$1.run(ProfileModificationAction.java:61)
        at
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Comment 5 Pascal Rapicault CLA 2008-04-03 09:53:14 EDT
The problem stems from the resolution procedure used when we are attaching the CUs to not return the same result than what we get from the sat4j resolver. Then after that all the bets are off.
Another thing I'm wondering is whether or not we can avoid the sorting.

The ideal solution here may be to hook into sat4j to get the attachment information.
Comment 6 Pascal Rapicault CLA 2008-04-08 09:01:23 EDT
*** Bug 226092 has been marked as a duplicate of this bug. ***
Comment 7 Tobias Södergren CLA 2008-04-08 09:27:14 EDT
I can verify that this is a problem when i try to remove Web Standard Tools from the list of installed Features:

Eclipse C/C++ Development Tools
Eclipse SDK
Web Standard Tools (WST) Project

The error appears as in comment #4.
Comment 8 Jed Anderson CLA 2008-04-08 09:57:28 EDT
We have re-written this method to read as follows.  I'm not sure if it just hides the real bug, but it does alleviate the AIOOBException problem.

	private InstallableUnitOperand[] sortOperations(InstallableUnitOperand[] toSort, List installOrder, List uninstallOrder) {
		List sorted = new ArrayList(toSort.length);
		for (Iterator i = installOrder.iterator(); i.hasNext();) {
			IInstallableUnit iu = (IInstallableUnit) i.next();
			for (int j = 0; j < toSort.length; j++) {
				InstallableUnitOperand operand = toSort[j];
				if (operand.first() == null && iu.equals(operand.second())) {
					sorted.add(operand);
					break;
				}
			}
		}
		for (Iterator i = uninstallOrder.iterator(); i.hasNext();) {
			IInstallableUnit iu = (IInstallableUnit) i.next();
			for (int j = 0; j < toSort.length; j++) {
				InstallableUnitOperand operand = toSort[j];
				if (operand.second() == null && iu.equals(operand.first())) {
					sorted.add(operand);
					break;
				}
			}
		}
		for (int i = 0; i < toSort.length; i++) {
			InstallableUnitOperand operand = toSort[i];
			if (operand.first() != null && operand.second() != null) {
				sorted.add(operand);
			}
		}
		return (InstallableUnitOperand[]) sorted.toArray(new InstallableUnitOperand[sorted.size()]);
	}
Comment 9 Pascal Rapicault CLA 2008-04-10 13:36:54 EDT
*** Bug 226543 has been marked as a duplicate of this bug. ***
Comment 10 Pascal Rapicault CLA 2008-04-14 22:49:28 EDT
New code from Jed released for the I-build.
Comment 11 Pascal Rapicault CLA 2008-04-14 22:49:48 EDT
*** Bug 226971 has been marked as a duplicate of this bug. ***
Comment 12 Pascal Rapicault CLA 2008-06-11 09:23:42 EDT
*** Bug 236595 has been marked as a duplicate of this bug. ***