[GLASSFISH-20233] getSingleResult Fails: java.lang.CloneNotSupportedException Created: 08/Apr/13  Updated: 01/Apr/14  Resolved: 06/Nov/13

Status: Resolved
Project: glassfish
Component/s: entity-persistence
Affects Version/s: 4.0_b83
Fix Version/s: 4.0_b85

Type: Bug Priority: Blocker
Reporter: reza_rahman Assignee: Mitesh Meswani
Resolution: Works as designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7


Attachments: File cargo-tracker-test.war    
Issue Links:
Dependency
blocks CARGOTRACKER-1 Make project work on latest GlassFish... Closed
Tags: 4_0_1-evangelists, 4_0_1-review

 Description   

A fairly simple JPA query that was working on b76 is now failing. Below is the error I get. The code that generates the error is here: http://java.net/projects/cargotracker/downloads. It can be build via Maven and deployed. The error will occur on deployment. Is this a known problem? Please advise.

Target Invocation Exception: java.lang.CloneNotSupportedException: java.util.Arrays$ArrayList
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:851)
at org.eclipse.persistence.internal.jpa.QueryImpl.performPreQueryFlush(QueryImpl.java:962)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:207)
at org.eclipse.persistence.internal.jpa.QueryImpl.getSingleResult(QueryImpl.java:516)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:400)
at net.java.cargotracker.infrastructure.persistence.jpa.JpaCargoRepository.find(JpaCargoRepository.java:23)
at net.java.cargotracker.domain.model.handling.HandlingEventFactory.findCargo(HandlingEventFactory.java:60)
at net.java.cargotracker.domain.model.handling.HandlingEventFactory.createHandlingEvent(HandlingEventFactory.java:44)
at net.java.cargotracker.application.util.SampleDataGenerator.loadSampleCargos(SampleDataGenerator.java:129)
at net.java.cargotracker.application.util.SampleDataGenerator.loadSampleData(SampleDataGenerator.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.ejb.containers.interceptors.BeanCallbackInterceptor.intercept(InterceptorManager.java:1035)
at com.sun.ejb.containers.interceptors.CallbackChainImpl.invokeNext(CallbackChainImpl.java:72)
at com.sun.ejb.containers.interceptors.CallbackInvocationContext.proceed(CallbackInvocationContext.java:205)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.ejb.containers.interceptors.CallbackInterceptor.intercept(InterceptorManager.java:986)
at com.sun.ejb.containers.interceptors.CallbackChainImpl.invokeNext(CallbackChainImpl.java:72)
at com.sun.ejb.containers.interceptors.CallbackInvocationContext.proceed(CallbackInvocationContext.java:205)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.init(SystemInterceptorProxy.java:125)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.ejb.containers.interceptors.CallbackInterceptor.intercept(InterceptorManager.java:986)
at com.sun.ejb.containers.interceptors.CallbackChainImpl.invokeNext(CallbackChainImpl.java:72)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:412)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:375)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:1949)
at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:460)
... 44 more
Caused by: Exception [EclipseLink-6055] (Eclipse Persistence Services - 2.5.0.v20130321-85f6cb0): org.eclipse.persistence.exceptions.QueryException
Exception Description: The method invocation of the method [protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException] on the object [[Leg

{id=33, voyage=Voyage 0100S, loadLocation=Hong Kong [CNHKG], unloadLocation=New York [USNYC], loadTime=Mon Mar 02 00:00:00 EST 2009, unloadTime=Thu Mar 05 00:00:00 EST 2009}

, Leg

{id=34, voyage=Voyage 0200T, loadLocation=New York [USNYC], unloadLocation=Dallas [USDAL], loadTime=Fri Mar 06 00:00:00 EST 2009, unloadTime=Sun Mar 08 00:00:00 EST 2009}

, Leg

{id=35, voyage=Voyage 0300A, loadLocation=Dallas [USDAL], unloadLocation=Helsinki [FIHEL], loadTime=Mon Mar 09 00:00:00 EDT 2009, unloadTime=Thu Mar 12 00:00:00 EDT 2009}

]], of class [class java.util.Arrays$ArrayList], triggered an exception.
Internal Exception: java.lang.reflect.InvocationTargetException
Target Invocation Exception: java.lang.CloneNotSupportedException: java.util.Arrays$ArrayList
at org.eclipse.persistence.exceptions.QueryException.methodInvocationFailed(QueryException.java:838)
at org.eclipse.persistence.internal.queries.InterfaceContainerPolicy.invokeCloneMethodOn(InterfaceContainerPolicy.java:245)
at org.eclipse.persistence.internal.queries.InterfaceContainerPolicy.cloneFor(InterfaceContainerPolicy.java:98)
at org.eclipse.persistence.mappings.CollectionMapping.buildBackupCloneForPartObject(CollectionMapping.java:186)
at org.eclipse.persistence.internal.indirection.IndirectionPolicy.backupCloneAttribute(IndirectionPolicy.java:74)
at org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy.backupCloneAttribute(TransparentIndirectionPolicy.java:76)
at org.eclipse.persistence.mappings.ForeignReferenceMapping.buildBackupClone(ForeignReferenceMapping.java:285)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildBackupClone(ObjectBuilder.java:502)
at org.eclipse.persistence.mappings.AggregateMapping.buildBackupClonePart(AggregateMapping.java:125)
at org.eclipse.persistence.mappings.AggregateMapping.buildBackupClone(AggregateMapping.java:114)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildBackupClone(ObjectBuilder.java:502)
at org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.buildBackupClone(DeferredChangeDetectionPolicy.java:225)
at org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.revertChanges(DeferredChangeDetectionPolicy.java:289)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.resumeUnitOfWork(UnitOfWorkImpl.java:5275)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:470)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:846)
... 80 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.invokeMethod(PrivilegedAccessHelper.java:409)
at org.eclipse.persistence.internal.queries.InterfaceContainerPolicy.invokeCloneMethodOn(InterfaceContainerPolicy.java:240)
... 94 more
Caused by: java.lang.CloneNotSupportedException: java.util.Arrays$ArrayList
at java.lang.Object.clone(Native Method)
... 100 more



 Comments   
Comment by reza_rahman [ 08/Apr/13 ]

I'm not sure if it is causing this issue, but I had to turn off EclipseLink weaving at least for now: http://java.net/jira/browse/GLASSFISH-20209.

Comment by Mitesh Meswani [ 09/Apr/13 ]

This is tracked by corresponding EclipseLink issue - https://bugs.eclipse.org/bugs/show_bug.cgi?id=405226

Comment by reza_rahman [ 09/Apr/13 ]

As suspected, works when weaving is turned back on.

Comment by reza_rahman [ 06/Oct/13 ]

I am getting this same error, but now with GlassFish embedded. Any idea what's going on?

Comment by reza_rahman [ 06/Oct/13 ]

Attaching simple test war demonstrating the resurfacing of this issue in GlassFish embedded, blocking unit testing.

Comment by reza_rahman [ 06/Oct/13 ]

I've attached the simple war demonstrating the issue. The war works fine on the current nightly GlassFish build. It fails with almost all versions of the embedded container. Below is the stack trace (using glassfish-embedded-all-4.0-b92.jar) and the code used for the embedded container:

Local Exception Stack: 
Exception [EclipseLink-6055] (Eclipse Persistence Services - 2.5.0.v20130417-5763b06): org.eclipse.persistence.exceptions.QueryException
Exception Description: The method invocation of the method [protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException] on the object [[]], of class [class java.util.Collections$EmptyList], triggered an exception.
Internal Exception: java.lang.reflect.InvocationTargetException
Target Invocation Exception: java.lang.CloneNotSupportedException: java.util.Collections$EmptyList
	at org.eclipse.persistence.exceptions.QueryException.methodInvocationFailed(QueryException.java:839)
	at org.eclipse.persistence.internal.queries.InterfaceContainerPolicy.invokeCloneMethodOn(InterfaceContainerPolicy.java:245)
	at org.eclipse.persistence.internal.queries.InterfaceContainerPolicy.cloneFor(InterfaceContainerPolicy.java:98)
	at org.eclipse.persistence.mappings.CollectionMapping.buildBackupCloneForPartObject(CollectionMapping.java:186)
	at org.eclipse.persistence.internal.indirection.IndirectionPolicy.backupCloneAttribute(IndirectionPolicy.java:74)
	at org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy.backupCloneAttribute(TransparentIndirectionPolicy.java:76)
	at org.eclipse.persistence.mappings.ForeignReferenceMapping.buildBackupClone(ForeignReferenceMapping.java:285)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildBackupClone(ObjectBuilder.java:505)
	at org.eclipse.persistence.mappings.AggregateMapping.buildBackupClonePart(AggregateMapping.java:125)
	at org.eclipse.persistence.mappings.AggregateMapping.buildBackupClone(AggregateMapping.java:114)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildBackupClone(ObjectBuilder.java:505)
	at org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.buildBackupClone(DeferredChangeDetectionPolicy.java:225)
	at org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.revertChanges(DeferredChangeDetectionPolicy.java:289)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.resumeUnitOfWork(UnitOfWorkImpl.java:5275)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.synchronizeAndResume(UnitOfWorkImpl.java:5224)
	at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.synchronizeAndResume(RepeatableWriteUnitOfWork.java:555)
	at org.eclipse.persistence.transaction.AbstractSynchronizationListener.afterCompletion(AbstractSynchronizationListener.java:228)
	at org.eclipse.persistence.transaction.JTASynchronizationListener.afterCompletion(JTASynchronizationListener.java:79)
	at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:557)
	at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:854)
	at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:719)
	at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:515)
	at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4475)
	at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:493)
	at com.sun.ejb.containers.AbstractSingletonContainer.access$000(AbstractSingletonContainer.java:81)
	at com.sun.ejb.containers.AbstractSingletonContainer$SingletonContextFactory.create(AbstractSingletonContainer.java:654)
	at com.sun.ejb.containers.AbstractSingletonContainer.instantiateSingletonInstance(AbstractSingletonContainer.java:396)
	at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:219)
	at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:180)
	at org.glassfish.ejb.startup.SingletonLifeCycleManager.doStartup(SingletonLifeCycleManager.java:158)
	at org.glassfish.ejb.startup.EjbApplication.start(EjbApplication.java:166)
	at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
	at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)
	at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:497)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
	at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
	at java.security.AccessController.doPrivileged(Native Method)
	at javax.security.auth.Subject.doAs(Subject.java:356)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
	at com.sun.enterprise.admin.cli.embeddable.DeployerImpl.deploy(DeployerImpl.java:133)
	at net.java.cargotracker.application.BookingServiceTest.testRegisterNew(BookingServiceTest.java:152)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
	at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.invokeMethod(PrivilegedAccessHelper.java:409)
	at org.eclipse.persistence.internal.queries.InterfaceContainerPolicy.invokeCloneMethodOn(InterfaceContainerPolicy.java:240)
	... 70 more
Caused by: java.lang.CloneNotSupportedException: java.util.Collections$EmptyList
	at java.lang.Object.clone(Native Method)
	... 76 more
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish();
glassfish.start();
File war = new File("c:\\temp\\cargo-tracker-test.war");
Deployer deployer = glassfish.getDeployer();
deployer.deploy(war);

It's even worse with glassfish-embedded-all-4.0.1-b01.jar and glassfish-embedded-all-4.0.1-b02.jar - the container can't even be bootstrapped.

Unit testing is all but impossible with these bugs - I think we need to look into what's going on with the embedded container builds quickly...

Comment by qiang.l.liu [ 06/Nov/13 ]

Dynamic Weaving is turned on whenever you run app in full server or embedded mode, unless you explicitly specify "org.glassfish.persistence.embedded.weaving.enabled" to false.

But in your test case(cargo-tracker), it looks like the entities are loaded(by the unit test classes) before the JPA container is deployed. So Weaving don't happen on the entities. You can enable Static Weaving when compiling to work around this issue. If this is a acceptable solution, I can provide the enable-Static-Weaving instructions.

There may be another issue with the test case, which is the http port of embedded server is 8181, but the test case use 8080 instead when run Jersy client. Please see test-ejb-jar.xml.

Generated at Thu Sep 03 09:57:16 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.