Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 323403 - NPE on missing Weaving VH getMethod on deploy validation requires better error message stating the application.xml deployment descriptor module order should be switched
Summary: NPE on missing Weaving VH getMethod on deploy validation requires better erro...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL: http://wiki.eclipse.org/EclipseLink/E...
Whiteboard:
Keywords:
Depends on:
Blocks: 323148
  Show dependency tree
 
Reported: 2010-08-23 12:00 EDT by Michael OBrien CLA
Modified: 2022-06-09 10:32 EDT (History)
1 user (show)

See Also:
michael.f.obrien: documentation+


Attachments
EAR (with JSF managed-bean element) that reproduces NPE exception when application.xml module order is war first (29.09 KB, application/x-zip-compressed)
2010-08-23 12:04 EDT, Michael OBrien CLA
no flags Details
EAR Eclipse Project Source (3) (with JSF managed-bean element) that reproduces NPE exception when application.xml module order is war first (52.16 KB, application/x-zip-compressed)
2010-08-23 12:05 EDT, Michael OBrien CLA
no flags Details
New DescriptorException specifically for "_persistence_*_vh" weaved methods that would have thrown a secondary NPE (39.39 KB, patch)
2010-08-23 15:01 EDT, Michael OBrien CLA
no flags Details | Diff
New 218 DescriptorException specifically for "_persistence_*_vh" weaved methods that would have thrown a secondary NPE (39.78 KB, patch)
2010-08-25 11:10 EDT, Michael OBrien CLA
no flags Details | Diff
Remove override of MethodAttributeAccessor function so there is no redirect of SDOMethodAttributAccessor for SDO (7.31 KB, patch)
2010-08-25 15:45 EDT, Michael OBrien CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael OBrien CLA 2010-08-23 12:00:22 EDT
>The following common NullPointerException occurs because weaving VH methods were not found.
The cause is the fact that because weaving is on globally or for a mapping via FetchType.LAZY - the validation check during the entityManager deploy will fail with a NPE on an expected value holder method that should have been weaved into the .class file

>Solution: Switch the order of modules in application.xml to load the module (usually ejb.jar) containing the injected EM/EMF
- the module (here a JSF managed-bean POJO in the WAR) that uses for example the Stateless session bean containing the @PersistenceContext injection (in the ejb.jar) should come after the ejb.jar in the EAR's application.xml deployment descriptor

>Another workaround is to disable weaving if you do not need it in the persistence.xml or by mapping via FetchType.EAGER

-------------------details--------------------
>Environment
- GlassFish 3.x or WebLogic 10.3.3+
- Container managed EntityManager as an injected @PersistenceContext resource on a @Stateless session bean - on the ejb.jar
- a JTA TX datasource on the server (here Derby 10.5.3.0)

>Exception
Exception [EclipseLink-60] (Eclipse Persistence Services - 2.2.0.qualifier): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [_persistence_set_left_vh] or [_persistence_get_left_vh] is not defined in the object [org.eclipse.persistence.example.jpa.server.business.Cell].
Internal Exception: java.lang.NoSuchMethodException: org.eclipse.persistence.example.jpa.server.business.Cell._persistence_get_left_vh()
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[left]
Descriptor: RelationalDescriptor(org.eclipse.persistence.example.jpa.server.business.Cell --> [DatabaseTable(EL_CELL)])

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:471)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:374)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:157)
	at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:243)
	Truncated. see log file for complete stacktrace

java.lang.NullPointerException
	at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getMethodReturnType(PrivilegedAccessHelper.java:327)
	at org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor.getGetMethodReturnType(MethodAttributeAccessor.java:126)
	at org.eclipse.persistence.mappings.ForeignReferenceMapping.validateBeforeInitialization(ForeignReferenceMapping.java:1709)
	at org.eclipse.persistence.descriptors.ClassDescriptor.validateBeforeInitialization(ClassDescriptor.java:5282)
	at org.eclipse.persistence.descriptors.ClassDescriptor.preInitialize(ClassDescriptor.java:3346)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:429)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:374)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:157)
	at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:243)
	at weblogic.deployment.PersistenceUnitInfoImpl.createEntityManagerFactory(PersistenceUnitInfoImpl.java:352)
	at weblogic.deployment.PersistenceUnitInfoImpl.createEntityManagerFactory(PersistenceUnitInfoImpl.java:332)
	at weblogic.deployment.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:134)
	at weblogic.deployment.AbstractPersistenceUnitRegistry.storeDescriptors(AbstractPersistenceUnitRegistry.java:336)
	at weblogic.deployment.AbstractPersistenceUnitRegistry.loadPersistenceDescriptor(AbstractPersistenceUnitRegistry.java:250)
	at weblogic.deployment.ModulePersistenceUnitRegistry.<init>(ModulePersistenceUnitRegistry.java:69)
	at weblogic.ejb.container.deployer.EJBModule.setupPersistenceUnitRegistry(EJBModule.java:221)
	at weblogic.ejb.container.deployer.EJBModule$1.execute(EJBModule.java:322)
	at weblogic.deployment.PersistenceUnitRegistryInitializer.setupPersistenceUnitRegistries(PersistenceUnitRegistryInitializer.java:62)
	at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:398)
	at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176)
	at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
	at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:507)
	at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
	at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:149)
	at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:45)
	at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:1221)
	at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
	at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:367)
	at weblogic.application.internal.EarDeployment.prepare(EarDeployment.java:58)
	at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:154)
	at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60)
	at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:207)
	at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:98)
	at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:217)
	at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:747)
	at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1216)
	at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:250)
	at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:159)
	at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:171)
	at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer.java:13)
	at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCallbackDeliverer.java:46)
	at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:528)
	at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
	at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
 

>Stacktrace
Oracle WebLogic Server 11gR1 PatchSet 2 at localhost [Oracle WebLogic Launch Configuration]	
  Oracle JRockit(R)[localhost:8453]	
    Daemon Thread [[STANDBY] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'] (Suspended (breakpoint at line 327 in PrivilegedAccessHelper))	
      PrivilegedAccessHelper.getMethodReturnType(Method) line: 327	
      MethodAttributeAccessor.getGetMethodReturnType(DatabaseMapping) line: 126	
      OneToOneMapping(ForeignReferenceMapping).validateBeforeInitialization(AbstractSession) line: 1709	
      RelationalDescriptor(ClassDescriptor).validateBeforeInitialization(AbstractSession) line: 5282	
      RelationalDescriptor(ClassDescriptor).preInitialize(AbstractSession) line: 3346	
      ServerSession(DatabaseSessionImpl).initializeDescriptors(Map) line: 429	
      ServerSession(DatabaseSessionImpl).initializeDescriptors() line: 406	
      EntityManagerSetupImpl.deploy(ClassLoader, Map) line: 374	
      EntityManagerFactoryImpl.getServerSession() line: 157	
      PersistenceProvider.createContainerEntityManagerFactory(PersistenceUnitInfo, Map) line: 243	
      PersistenceUnitInfoImpl.createEntityManagerFactory(boolean) line: 352	
      PersistenceUnitInfoImpl.createEntityManagerFactory() line: 332	
      PersistenceUnitInfoImpl.<init>(PersistenceUnitBean, PersistenceUnitConfigurationBean, GenericClassLoader, String, URL, URL) line: 134	
      ModulePersistenceUnitRegistry(AbstractPersistenceUnitRegistry).storeDescriptors(Map, Map) line: 336	
      ModulePersistenceUnitRegistry(AbstractPersistenceUnitRegistry).loadPersistenceDescriptor(VirtualJarFile, boolean, File) line: 250	
      ModulePersistenceUnitRegistry.<init>(GenericClassLoader, ApplicationContextInternal, Module, boolean) line: 69	
      EJBModule.setupPersistenceUnitRegistry() line: 221	
      EJBModule$1.execute() line: 322	
      PersistenceUnitRegistryInitializer.setupPersistenceUnitRegistries() line: 62	
      WebAppModule.prepare() line: 398	
      ScopedModuleDriver.prepare() line: 176	
      ModuleListenerInvoker.prepare() line: 199	
      DeploymentCallbackFlow$1.next(Object) line: 507	
      StateMachineDriver.nextState(StateChange, Object[]) line: 41	
      DeploymentCallbackFlow.prepare(Module[]) line: 149	
      DeploymentCallbackFlow.prepare() line: 45	
      BaseDeployment$1.next(Object) line: 1221	
      StateMachineDriver.nextState(StateChange, Object[]) line: 41	
      EarDeployment(BaseDeployment).prepare(DeploymentContext) line: 367	
      EarDeployment.prepare(DeploymentContext) line: 58	
      DeploymentStateChecker.prepare(DeploymentContext) line: 154	
      AppContainerInvoker.prepare(DeploymentContext) line: 60	
      ActivateOperation.createAndPrepareContainer() line: 207	
      ActivateOperation.doPrepare() line: 98	
      ActivateOperation(AbstractOperation).prepare() line: 217	
      DeploymentManager.handleDeploymentPrepare(Deployment, DeploymentManager$DeploymentRequestInfo) line: 747	
      DeploymentManager.prepareDeploymentList(ArrayList, DeploymentContext) line: 1216	
      DeploymentManager.handlePrepare(DeploymentContext) line: 250	
      DeploymentServiceDispatcher.prepare(DeploymentContext) line: 159	
      DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentContext) line: 171	
      DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer, DeploymentContext) line: 13	
      DeploymentReceiverCallbackDeliverer$1.run() line: 46	
      SelfTuningWorkManagerImpl$WorkAdapterImpl.run() line: 528	
      ExecuteThread.execute(Runnable) line: 201	
      ExecuteThread.run() line: 173	

>As you can see we have the weaving method names but not the methods themselves
this	MethodAttributeAccessor  (id=12548)	
	attributeName	"right" (id=12549)	
	getMethod	null	
	getMethodName	"_persistence_get_right_vh" (id=12563)	
	isReadOnly	false	
	isWriteOnly	false	
	setMethod	null	
	setMethodName	"_persistence_set_right_vh" (id=12564)	
mapping	OneToOneMapping  (id=12547)	
getMethod	null	


>cause: calling method.getReturnType() when method == null without checking this
PrivilegedAccessHelper.java:326
    public static Class getMethodReturnType(final Method method) {
        // 323148: a null method as a possible problem with module ordering breaking weaving - has been trapped by implementors of this method.
        return method.getReturnType();
    }


>The cause of the NPE was a group effort between Michael O'Brien, Douglas Clarke and Steve Button.
>The following open issues benefit from this fix.
Re: [eclipselink-users] OneToOne AND ManyToOne Mapping works with FetchType.EAGER but not with FetchType.LAZY -> Exception when deploying (SGES 2.1)  
http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg05147.html
Re: [eclipselink-users] JPA not working inside Equinox but fine in unit tests
http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg05146.html
Re: [eclipselink-users] Can't deploy when using LAZY, can deply when using EAGER
http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg05145.html
Re: [eclipselink-users] NPE when running with option javaagent:eclipselink.jar 
http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg05144.html
JPA test suties failed in OSGi with enabled weaving 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=293193#c7
Comment 1 Michael OBrien CLA 2010-08-23 12:04:31 EDT
Created attachment 177233 [details]
EAR (with JSF managed-bean element) that reproduces NPE exception when application.xml module order is war first
Comment 2 Michael OBrien CLA 2010-08-23 12:05:07 EDT
Created attachment 177234 [details]
EAR Eclipse Project Source (3) (with JSF managed-bean element) that reproduces NPE exception when application.xml module order is war first
Comment 3 Michael OBrien CLA 2010-08-23 15:01:44 EDT
Created attachment 177253 [details]
New DescriptorException specifically for "_persistence_*_vh" weaved methods that would have thrown a secondary NPE

>New DescriptorException specifically for "_persistence_*_vh" weaved methods that would have thrown a secondary NPE
Exception [EclipseLink-218] (Eclipse Persistence Services - 2.2.0.qualifier): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A NullPointerException would have occurred accessing a non-existent weaved method [_persistence_get_right_vh] for the mapping [org.eclipse.persistence.mappings.OneToOneMapping[right]].  The class was not weaved properly - check the module order in the application.xml deployment descriptor and verify that the module containing the persistence unit is ahead of any module that uses it.
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:471)
Comment 4 Michael OBrien CLA 2010-08-23 17:25:08 EDT
>post patch to eclipselink-dev for review
http://dev.eclipse.org/mhonarc/lists/eclipselink-dev/msg04791.html
Comment 5 Michael OBrien CLA 2010-08-23 17:32:40 EDT
>Note: the secondary NPE on missing _vh_ weaved functions in bug # 322679 will show this change after checkin
Comment 6 Michael OBrien CLA 2010-08-25 11:10:56 EDT
Created attachment 177431 [details]
New 218 DescriptorException specifically for "_persistence_*_vh" weaved methods that would have thrown a secondary NPE
Comment 7 Michael OBrien CLA 2010-08-25 15:45:06 EDT
Created attachment 177469 [details]
Remove override of MethodAttributeAccessor function so there is no redirect of SDOMethodAttributAccessor for SDO
Comment 8 Michael OBrien CLA 2010-08-25 15:51:19 EDT
>See checkin of new 218 exception patch
https://fisheye2.atlassian.com/changelog/eclipselink/?cs=8081
>See JPA fix that fixes SDO temporary redirection of SDOMethodAttributeAccessor.getGetMethodReturnType() to superclass
https://fisheye2.atlassian.com/changelog/eclipselink/?cs=8085
Comment 9 Michael OBrien CLA 2010-08-25 16:11:36 EDT
>retest 8085 on WebLogic with a broken JSF ear in web/ejb order - OK (expected exception on deploy)
Exception Description: A NullPointerException would have occurred accessing a non-existent weaved _vh_ method [_persistence_get_right_vh].  The class was not weaved properly - for EE deployments, check the module order in the application.xml deployment descriptor and verify that the module containing the persistence unit is ahead of any other module that uses it.
- reversing the application.xml order failed to print the exception on deploy - as expected, where JSF was initialized fine in this case
25-Aug-2010 4:04:34 PM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra (1.2_09-20081212-SNAPSHOT) for context '/enterprise_jsf'
Comment 10 Michael OBrien CLA 2010-08-25 16:13:47 EDT
>See rev# 8081, 8085 for new 218 DescriptorException
Comment 11 Eclipse Webmaster CLA 2022-06-09 10:32:29 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink