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

Bug 320276

Summary: Intermittent issue in DescriptorQueryManagerMultithreadedTest$DescriptorQueryManagerAddQueryTest
Product: z_Archived Reporter: Andrei Ilitchev <andrei.ilitchev>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
the patch none

Description Andrei Ilitchev CLA 2010-07-19 11:02:00 EDT
DescriptorQueryManagerMultithreadedTest$DescriptorQueryManagerAddQueryTest
Exception Description: Fatal error occurred. Internal Exception: java.util.NoSuchElementException

Local Exception Stack:
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.1.1.v20100717-r7852): org.eclipse.persistence.testing.framework.TestErrorException
Exception Description: Fatal error occurred.
Internal Exception: java.util.NoSuchElementException
at org.eclipse.persistence.testing.framework.TestCase.execute(TestCase.java:164)
at org.eclipse.persistence.testing.framework.TestCase.runBare(TestCase.java:263)
at org.eclipse.persistence.testing.framework.TestExecutor.execute(TestExecutor.java:248)
at org.eclipse.persistence.testing.tests.simultaneous.TestExecutorWithClientSession.runTest(TestExecutorWithClientSession.java:153)
at org.eclipse.persistence.testing.framework.ui.SynchronizedTestExecutor.run(SynchronizedTestExecutor.java:61)
Caused by: java.util.NoSuchElementException
at org.eclipse.persistence.internal.helper.NonSynchronizedVector.firstElement(NonSynchronizedVector.java:172)
at org.eclipse.persistence.descriptors.DescriptorQueryManager.getLocalQuery(DescriptorQueryManager.java:535)
at org.eclipse.persistence.descriptors.DescriptorQueryManager.getQuery(DescriptorQueryManager.java:499)
at org.eclipse.persistence.descriptors.DescriptorQueryManager.getQuery(DescriptorQueryManager.java:484)
at org.eclipse.persistence.testing.tests.simultaneous.DescriptorQueryManagerMultithreadedTest$DescriptorQueryManagerAddQueryTest.verify(DescriptorQueryManagerMultithreadedTest.java:70)
at org.eclipse.persistence.testing.framework.TestCase.execute(TestCase.java:155)


This happens when a very narrow window is hit: in DescriptorQueryManager.addQuery method one thread has already removed the ith query but hasn't yet added the new one;
another thread at this moment in DescriptorQueryManager.getLocalQuery() has verified that queries.size()==1 (before the first thread has removed the query); then the next statement queries.firstElement() throws exception - because the first thread has removed the only element there was.

The fix is simple: in DescriptorQueryManager.addQuery instead of:
                    queriesByName.remove(i);
                    queriesByName.add(i, query);
use:
                    queriesByName.set(i, query);
Comment 1 Andrei Ilitchev CLA 2010-07-19 11:05:01 EDT
Created attachment 174627 [details]
the patch
Comment 2 Andrei Ilitchev CLA 2010-07-19 11:10:25 EDT
Fixed in bot trunk and 2.1.1
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:15:52 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:31:22 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink