Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 330561

Summary: NullPointerException when weaving is false
Product: [RT] Gemini.JPA Reporter: Alex Blewitt <alex.blewitt>
Component: CoreAssignee: Michael Keith <michael.keith>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Alex Blewitt CLA 2010-11-18 08:14:30 EST
Build Identifier: 1.0.0.M2-SNAPSHOT

If eclipse.weaving is set to false, a NullPointerException subsequently occurs.

java.lang.NullPointerException
	org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:250)
	org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchives(JPAInitializer.java:138)
	org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfo(JPAInitializer.java:125)
	org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:98)


This occurs because the instance of the GeminiOSGiInitializer.initializationClassLoader is null, and it's trying to execute:

        String descriptorPath = (String) m.get(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML);
        final Set<Archive> pars;
        if (descriptorPath != null) {
            pars = PersistenceUnitProcessor.findPersistenceArchives(initializationClassloader, descriptorPath);
        } else {
            pars = PersistenceUnitProcessor.findPersistenceArchives(initializationClassloader);
        }

Whichever path occurs (FWIW mine found the META-INF/persistence.xml) the initializationClassLoader is null, which leads to an NPE on the next call:

                Enumeration<URL> resources = loader.getResources(descriptorPath);

I believe this is marked as null because the eclipselink.weaving was set to 'false' in my persistence XML, which leads to the 'checkWeaving' call in GeminiOSgi's parent:

        if ((weaving != null) && ((weaving.equalsIgnoreCase("false")) || (weaving.equalsIgnoreCase("static")))){
            shouldCreateInternalLoader = false;
        }

As a result, the initializationClassLoader is null

Reproducible: Always

Steps to Reproduce:
I believe this is triggered with an explicit instruction to disable weaving.
Comment 1 Alex Blewitt CLA 2010-11-18 08:31:15 EST
Hmm. I get the same error when I try eclipse.weaving=true in the persistence.xml.
Comment 2 Alex Blewitt CLA 2010-11-18 08:32:41 EST
BTW I'm using EclipseLink 2.1.1-jpa which exposes the problem.

The property map 'm' contains the classloader so I wonder if it's a bug there using the initializationClassLoader instead of the supplied one?
Comment 3 Alex Blewitt CLA 2010-11-18 08:55:53 EST
Some other debugging inforamation that may be of use:

1) I'm calling 'EntityManagerFactory emf = Persistence			.createEntityManagerFactory("jpa");' to trigger this

2) The OSGi console shows the service to be available:

osgi> services (objectClass=javax.*)
{javax.persistence.spi.PersistenceProvider}={javax.persistence.provider=org.eclipse.persistence.jpa.
PersistenceProvider, osgi.jpa.provider.version=1.0.0.M2-incubation, service.id=103}
  Registered by bundle: org.eclipse.gemini.jpa_1.0.0.M2-incubation [77]
  No bundles using service.
{javax.persistence.EntityManagerFactory}={osgi.managed.bundles=com.example, osgi.unit.version=1.0.0.SNAPSHOT, osgi.unit.name=jpa, osgi.unit.provider=org.eclipse.persistence.jpa.PersistenceProvider, service.id=109}
  Registered by bundle: com.example [84]
  Bundles using service:
    org.eclipse.gemini.javax.persistence_2.0.0.M2-incubation [25]

3) I'm running this in Virgo, and the bundles have been loaded as required with the PAR deployed containing the JPA bundle (above)
Comment 4 Alex Blewitt CLA 2010-11-18 09:04:16 EST
OK. As a further follow up to this, the acquisition of the service is succeeding, so I'm getting the entity manager factory, but it's falling at the createEntityManager() call.
Comment 5 Michael Keith CLA 2010-11-18 09:14:50 EST
Duplicate of 328072. Fixed in pending M3 drop.

(Thanks for your work looking into it, though :-)
Comment 6 Michael Keith CLA 2010-11-18 09:16:01 EST

*** This bug has been marked as a duplicate of bug 328072 ***
Comment 7 Alex Blewitt CLA 2010-11-18 09:29:10 EST
Good to know. Any idea when the pending M3 drop is? I don't think there's a workaround around this, is there?