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

Bug 362180

Summary: ConcurrentModificationException on predeploy for AttributeOverride
Product: z_Archived Reporter: Florian Wunderlich <fwunderlich>
Component: EclipselinkAssignee: Guy Pelletier <guy.pelletier>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: eclipselink.orm-inbox, guy.pelletier, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Simple test case that reproduces the problem
none
Proposed changes none

Description Florian Wunderlich CLA 2011-10-27 07:19:38 EDT
Build Identifier: 

This bug occurs only on EclipseLink-2.3.0.

If nested Embeddables are used, and an Embeddable contains an AttributeOverride for a field in a subordinate Embeddable, the following Exception is thrown:

java.util.ConcurrentModificationException
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1385)

This might have to do with runtime instrumentation, as the Exception is raised during instrumentation. The full stack trace is:

Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:323)
	at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [aerztebewertungen] failed.
Internal Exception: java.util.ConcurrentModificationException
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1385)
	at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
	at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.initPersistenceUnits(JPAInitializer.java:306)
	at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.initialize(JPAInitializer.java:265)
	at org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializer.getJavaSECMPInitializer(JavaSECMPInitializer.java:82)
	at org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializer.getJavaSECMPInitializerFromAgent(JavaSECMPInitializer.java:66)
	at org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializer.initializeFromAgent(JavaSECMPInitializer.java:168)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializerAgent.initializeFromAgent(JavaSECMPInitializerAgent.java:47)
	at org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializerAgent.premain(JavaSECMPInitializerAgent.java:39)
	... 6 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [xxx] failed.
Internal Exception: java.util.ConcurrentModificationException
	at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:221)
	... 19 more
Caused by: java.util.ConcurrentModificationException
	at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
	at java.util.HashMap$KeyIterator.next(HashMap.java:828)
	at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage1(MetadataProject.java:1597)
	at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:517)
	at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:526)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1320)
	... 18 more
FATAL ERROR in native method: processing of -javaagent failed

I will attach a simple test case with which the problem can be reproduced.

Reproducible: Always

Steps to Reproduce:
1. Unzip test case, and create a persistence.xml
2. Start application with runtime instrumentation
3. Observe that the Exception is not thrown when the AttributeOverrides is removed
Comment 1 Florian Wunderlich CLA 2011-10-27 07:20:29 EDT
Created attachment 206064 [details]
Simple test case that reproduces the problem
Comment 2 Florian Wunderlich CLA 2011-10-27 07:22:32 EDT
To elaborate a bit on the test case:

TheEntity refers to ExtendedEmbeddable,
  which inherits from BasicEmbeddable,
    which refers to Primitive with an AttributeOverride.

The interesting part:

@Embeddable
@MappedSuperclass
public class BasicEmbeddable
{
  @Embedded
  @AttributeOverrides({
    @AttributeOverride(name = "field",
      column = @Column(nullable = true))
  })
  private Primitive primitive;

  ...
}

@Embeddable
public class Primitive
{
  @Column(nullable = false)
  private double field;

  ...
}
Comment 3 Tom Ware CLA 2011-10-31 13:44:39 EDT
When you say "bug occurs only on EclipseLink-2.3.0".  Do you mean the issue did not exist on previous versions?
Comment 4 Florian Wunderlich CLA 2011-11-01 06:45:31 EDT
The ConcurrentModificationException was not thrown with EclipseLink-2.1.0; instead, the AttributeOverrides was simply ignored.

I have not tested with any other version of EclipseLink.
Comment 5 Tom Ware CLA 2011-11-09 13:49:07 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 6 Guy Pelletier CLA 2011-11-10 11:04:19 EST
Does the exception still occur if you remove the @Embeddable declaration on Basic Embeddable?

That class shouldn't be both an @Embeddable and a @MappedSuperclass.
Comment 7 Tom Ware CLA 2011-12-02 10:27:05 EST
Correcting target milestone to next milestone that will include community-submitted bugs.
Comment 8 Guy Pelletier CLA 2012-04-04 13:29:17 EDT
Created attachment 213600 [details]
Proposed changes
Comment 9 Guy Pelletier CLA 2012-04-04 15:01:12 EDT
Changes have been submitted.

Verified by: Andrei Ilitchev

Tests: Updated inherited model to expose error during metadata processing. With fix in place, error goes away and FullRegressionTestSuite passes successfully.
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:07:58 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 11 Eclipse Webmaster CLA 2022-06-09 10:15:44 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink