Skip to content

Commit

Permalink
JDK 11 build and test fix (#1967)
Browse files Browse the repository at this point in the history
It seems, that code change introduced in #1959 doesn't work correctly on JDK 11 (17 and 21 works).
It's about following line
Map visitedObjects = new IdentityHashMap(values.stream().collect(Collectors.summingInt(Set::size)));

Issue is presented by following EL test error:

NestedUnitOfWorkDeleteNestedNewObjectTest

Exception Description: Fatal error occurred. Internal Exception: java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.util.Map (java.lang.Integer and java.util.Map are in module java.base of loader 'bootstrap')

Local Exception Stack:
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.7.14.qualifier): org.eclipse.persistence.testing.framework.TestErrorException
Exception Description: Fatal error occurred.
Internal Exception: java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.util.Map (java.lang.Integer and java.util.Map are in module java.base of loader 'bootstrap')
at org.eclipse.persistence.testing.framework.TestCase.execute(TestCase.java:168)
at org.eclipse.persistence.testing.framework.TestCase.runBare(TestCase.java:267)
at org.eclipse.persistence.testing.framework.TestExecutor.execute(TestExecutor.java:250)
at org.eclipse.persistence.testing.framework.TestSuite.execute(TestSuite.java:82)
at org.eclipse.persistence.testing.framework.TestCollection.run(TestCollection.java:315)
at org.eclipse.persistence.testing.framework.TestExecutor.execute(TestExecutor.java:250)
at org.eclipse.persistence.testing.framework.TestModel.execute(TestModel.java:213)
at org.eclipse.persistence.testing.framework.TestCollection.run(TestCollection.java:315)
at org.eclipse.persistence.testing.framework.TestExecutor.execute(TestExecutor.java:250)
at org.eclipse.persistence.testing.framework.TestModel.execute(TestModel.java:213)
at org.eclipse.persistence.testing.framework.TestCollection.run(TestCollection.java:315)
Caused by: java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.util.Map (java.lang.Integer and java.util.Map are in module java.base of loader 'bootstrap')
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:812)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitNestedUnitOfWork(UnitOfWorkImpl.java:1389)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commit(UnitOfWorkImpl.java:1184)
at org.eclipse.persistence.testing.tests.unitofwork.NestedUnitOfWorkDeleteNestedNewObjectTest.test(NestedUnitOfWorkDeleteNestedNewObjectTest.java:44)
at org.eclipse.persistence.testing.framework.TestCase.executeTest(TestCase.java:547)
at org.eclipse.persistence.testing.framework.TestCase.execute(TestCase.java:158) 

it happens only if product (EclipseLink) is build by JDK 11.
Test itself should be called with any JDK (11, 17, 21).
Origin lambda is refactored into more "classical" style.

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
  • Loading branch information
rfelcman committed Oct 11, 2023
1 parent e712276 commit 01fa76f
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,11 @@ public UnitOfWorkChangeSet calculateChanges(Map registeredObjects, UnitOfWorkCha
// these are the objects remaining in the UnitOfWork privateOwnedObjects map
if (hasPrivateOwnedObjects()) {
Collection<Set> values = getPrivateOwnedObjects().values();
Map visitedObjects = new IdentityHashMap(values.stream().collect(Collectors.summingInt(Set::size)));
int initialSize = 0;
for (Set value: values) {
initialSize += value.size();
}
Map visitedObjects = new IdentityHashMap(initialSize);
for (Set privateOwnedObjects : values) {
for (Object objectToRemove : privateOwnedObjects) {
performRemovePrivateOwnedObjectFromChangeSet(objectToRemove, visitedObjects);
Expand Down

0 comments on commit 01fa76f

Please sign in to comment.