Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 305731 - NPE when loading the repsitory
Summary: NPE when loading the repsitory
Status: CLOSED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: p2 (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P2 blocker (vote)
Target Milestone: ---   Edit
Assignee: P2 Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 305636
  Show dependency tree
 
Reported: 2010-03-12 14:59 EST by Angel Vera CLA
Modified: 2010-04-05 23:03 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Angel Vera CLA 2010-03-12 14:59:42 EST
We are trying to declare our WTP M6 driver, and we found a NPE that is blocking core functionality in one of our plugins. Thus, this defect is of high importance to us.

The following the stack trace that we are getting and I suspect this is due to some of the latest changes that we have had to adopt for P2. 

java.lang.NullPointerException
	at org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository.publishRepositoryReferences(LocalMetadataRepository.java:179)
	at org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository.initialize(LocalMetadataRepository.java:172)
	at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryIO$Parser$RepositoryHandler.finished(MetadataRepositoryIO.java:329)
	at org.eclipse.equinox.internal.p2.persistence.XMLParser$AbstractHandler.endElement(XMLParser.java:188)
	at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryIO$Parser.parse(MetadataRepositoryIO.java:211)
	at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryIO.read(MetadataRepositoryIO.java:65)
	at org.eclipse.equinox.internal.p2.metadata.repository.SimpleMetadataRepositoryFactory.load(SimpleMetadataRepositoryFactory.java:104)
	at org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory.loadRepository(UpdateSiteMetadataRepositoryFactory.java:76)
	at org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory.load(UpdateSiteMetadataRepositoryFactory.java:52)
	at org.eclipse.wst.server.discovery.internal.model.ExtensionUpdateSite.getExtensions(ExtensionUpdateSite.java:67)
	at org.eclipse.wst.server.discovery.internal.ExtensionUtility$1.run(ExtensionUtility.java:200)
Comment 1 Pascal Rapicault CLA 2010-03-12 15:08:21 EST
which site do you get that against?
Comment 2 Angel Vera CLA 2010-03-12 15:08:47 EST
I should mentioned that this happens on any of the following repositories URLs:
   <site url="http://download.eclipse.org/webtools/updates/"/>
   <site url="http://www.apache.org/dist/geronimo/eclipse/updates/"/>
   <site url="http://public.dhe.ibm.com/software/websphere/wasce/updates/"/>
Comment 3 Angel Vera CLA 2010-03-12 15:14:34 EST
And this is the call that we are doing: 
IMetadataRepository repo = mrf.load(url2, IRepositoryManager.REPOSITORIES_ALL, monitor);
Comment 4 Andrew Niefer CLA 2010-03-12 15:17:49 EST
The NPE is a null agent, who is creating the UpdateSiteMetadataRepositoryFactory?

If 
org.eclipse.wst.server.discovery.internal.model.ExtensionUpdateSite.getExtensions(ExtensionUpdateSite.java:67)
is instantiating the factory, it will also need to call factory#setAgent

You can get an agent with
(IProvisioningAgent) ServiceHelper.getService(getContext(), IProvisioningAgent.SERVICE_NAME);
Comment 5 Pascal Rapicault CLA 2010-03-12 15:19:22 EST
I don't get any of these errors when I load these repos in the p2 ui.
Comment 6 Pascal Rapicault CLA 2010-03-12 15:20:12 EST
If I remember correctly you initialize the repository on your own and you may be passing the wrong argument in.
Comment 7 Andrew Niefer CLA 2010-03-12 15:22:44 EST
(In reply to comment #4)
> You can get an agent with
> (IProvisioningAgent) ServiceHelper.getService(getContext(),
> IProvisioningAgent.SERVICE_NAME);

Sorry, ServiceHelper is not API, you'll need to do an appropriate service lookup with a BundleContext
Comment 8 DJ Houghton CLA 2010-03-12 15:26:27 EST
I added ExtensionUtility#getAgent as a helper. All service lookups should then be done through the acquired agent.
Comment 9 Angel Vera CLA 2010-03-12 16:47:16 EST
Thanks for the help. That helps, I would expect a better exception to be thrown instead of an NPE. So it would be nice to get that fix. 

I am now getting problems with the query.. any clues?

java.lang.IllegalArgumentException: IMatchExpression cannot be turned into a context expression
	at org.eclipse.equinox.internal.p2.metadata.expression.ExpressionFactory.contextExpression(ExpressionFactory.java:61)
	at org.eclipse.equinox.p2.query.ExpressionQuery.<init>(ExpressionQuery.java:31)
	at org.eclipse.wst.server.discovery.internal.model.ExtensionUpdateSite.getExtensions(ExtensionUpdateSite.java:106)
	at org.eclipse.wst.server.discovery.internal.ExtensionUtility$1.run(ExtensionUtility.java:200)
Comment 10 DJ Houghton CLA 2010-03-15 15:23:39 EDT
Maybe Thomas can offer some insight here.
Comment 11 Thomas Hallgren CLA 2010-03-15 17:27:06 EDT
I don't have the source of wst.server.discovery available right now but from the looks of it, an IMatchExpression is passed into the ExpressionQuery constructor.

Try using the ExpressionMatchQuery instead when creating a query for an IMatchExpression.
Comment 12 Angel Vera CLA 2010-03-31 17:19:51 EDT
(In reply to comment #11)
Okay I got pass that point now. 

I am now finding that SimplePlanner doesn't contain an implementation of createChangeRequest, which we use during: org.eclipse.wst.server.discovery.internal.model.Extension.getProvisioningPlan(boolean, IProgressMonitor)
Comment 13 Angel Vera CLA 2010-04-01 07:13:52 EDT
(In reply to comment #12)
I wanted to provide more details on what we are actually doing, you can take a look at the code in HEAD here: http://dev.eclipse.org/viewcvs/index.cgi/servertools/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/model/Extension.java?root=WebTools_Project&view=markup


What we are trying to do is to create a Provisioning plan, but in order to get the plan we need to calculate an IProfileChangeRequest, which we do using: 

IProfileChangeRequest pcr = planner.createChangeRequest(profile);
but that is comming back with NULL because SimplePlanner, doesn't implement that method.
Comment 14 Angel Vera CLA 2010-04-01 15:40:38 EDT
I have increased the priority on this bug, since I want to get this fix for WTP M7, and I am now fully looking into how to fix this problem to get our function working.
Comment 15 Thomas Hallgren CLA 2010-04-01 18:50:00 EDT
I'm looking at the stack-trace from comment 9. I think that problem is caused by line 80 in the ExpressionUtil:

 query = new ExpressionQuery<IInstallableUnit>(IInstallableUnit.class, requirement.getMatches());

Try replacing that line with:

 query = QueryUtil.createMatchQuery(requirement.getMatches());

I see that you have a MatchQuery subclass (the PatternInstallableUnitQuery) which matches names that ends with a string. I would advice you to change that. Replace this:

 query = new PatternInstallableUnitQuery("org.eclipse.wst.server.core.serverAdapter");

with this:

 query = QueryUtil.createMatchQuery("id ~= /*org.eclipse.wst.server.core.serverAdapter/");

I don't know what's going on with the provisioning plan. Perhaps Pascal has more insight on that.
Comment 16 Angel Vera CLA 2010-04-05 11:24:57 EDT
(In reply to comment #15)
Thanks Thomas. 

I am able to remove the PatternInstallableUnitQuery. It would be nice to add to the java docs of .createMatchQuery that it accepts RE, and perhaps some simple examples on how to search for ids and other fields. I was trying to use it but I didn't figure out what I needed to pass in.
Comment 17 Angel Vera CLA 2010-04-05 11:25:39 EDT
Pascal, 

Any ideas on comment #13 ?
Comment 18 Pascal Rapicault CLA 2010-04-05 23:03:28 EDT
The planner method has been properly implemented.