Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 446236 - IndirectList is missing the new sort method introduced in Java 8 (Java 1.8.0)
Summary: IndirectList is missing the new sort method introduced in Java 8 (Java 1.8.0)
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 critical with 6 votes (vote)
Target Milestone: ---   Edit
Assignee: Tomas Kraus CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 450821 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-10-07 19:02 EDT by David Mulligan CLA
Modified: 2022-06-09 10:10 EDT (History)
6 users (show)

See Also:


Attachments
Added sort method and jUnit tests (44.92 KB, patch)
2014-10-20 08:10 EDT, Tomas Kraus CLA
tomas.kraus: review+
lukas.jungmann: review+
Details | Diff
Final cosmetic changes (8.77 KB, patch)
2014-10-29 06:21 EDT, Tomas Kraus CLA
tomas.kraus: review+
Details | Diff
Fixed failing junits, optimized platform code (22.29 KB, patch)
2014-10-29 06:21 EDT, Tomas Kraus CLA
tomas.kraus: review+
Details | Diff
patch adding all jdk8 collection methods (138.34 KB, patch)
2015-04-21 06:17 EDT, Lukas Jungmann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Mulligan CLA 2014-10-07 19:02:29 EDT
Java 8 introduced sort(Comparator<? super E> c) to the List interface and Vector classes.  IndirectList extends Vector passing most method calls to the indirect collection delegate.  Since the sort method is missing, the call goes to the super class and not to the delegate causing the attempt to fail silently.  

I suspect that the implementation should look a lot like:

/**
 * @see java.util.Vector#sort(Comparator<? super E> c)
 */
public synchronized void sort(Comparator<? super E> c) {
	getDelegate().sort(c);
}
Comment 1 David Mulligan CLA 2014-10-07 19:02:38 EDT
I would recommend examining the collections API further for changes like this one.
Comment 2 Tomas Kraus CLA 2014-10-20 08:10:19 EDT
Created attachment 248006 [details]
Added sort method and jUnit tests

Added method to call sort on Vector stored inside IndirectList when such a metod is available (since JDK 1.8). It will throw UnsupportedOperationException exception with older JDK.
Also IndirectList was updated to have generic type as any other current collection in Java. I would like to introduce this into rest of Indirect collections too.

Pushed into master:
http://git.eclipse.org/c/eclipselink/eclipselink.runtime.git/commit/?id=f3780a031a5523442398b06c81342bbc525f0640
Comment 3 Lukas Jungmann CLA 2014-10-24 01:37:14 EDT
Comment on attachment 248006 [details]
Added sort method and jUnit tests

Resolve this if fixed already, pls. Thx
Comment 4 Tomas Kraus CLA 2014-10-29 06:21:12 EDT
Created attachment 248251 [details]
Final cosmetic changes
Comment 5 Tomas Kraus CLA 2014-10-29 06:21:37 EDT
Created attachment 248252 [details]
Fixed failing junits, optimized platform code
Comment 7 Lukas Jungmann CLA 2014-11-10 07:05:22 EST
*** Bug 450821 has been marked as a duplicate of this bug. ***
Comment 8 Wolfgang Fahl CLA 2014-11-10 09:04:36 EST
I'd like to check the unit test of http://stackoverflow.com/questions/26816650/java8-collections-sort-sometimes-does-not-sort-jpa-returned-lists
against the current version.
Comment 9 David Mulligan CLA 2015-01-30 17:43:14 EST
There are still some new Java 8 methods missing from IndirectList.

A partial list of methods still missing from IndirectList are:
forEach(Consumer)
removeIf(Predicate)
removeRange(int, int)
replaceAll(UnaryOperator)
spliterator()

Also IndirectMap needs similar generics treatment and missing methods added.  A partial list of methods IndirectMap is missing are:
compute(K, BiFunction)
computeIfAbsent(K, Function)
computeIfPresent(K, BiFunction)
forEach(BiConsumer)
getOrDefault(Object, V)
putIfAbsent(K, V)
replace(K,V)
replace(K,V,V)
replaceAll(BiFunction)

It is worth considering implementing Map, Cloneable, and Serializable instead of extending Hashtable.  Once you do this you will see the missing methods easier as the new methods listed above are in the Map interface.

I still wonder which other Java 8 changes have been missed.
Comment 10 Lukas Jungmann CLA 2015-04-21 06:17:49 EDT
Created attachment 252577 [details]
patch adding all jdk8 collection methods
Comment 12 Robert Nagajek CLA 2015-05-17 01:48:02 EDT
The resolution has bugs. It looks like it's present in release 2.6.0, but the update of Indirect* classes hasn't been replaced in all locations.

OrderedListContainerPolicy directly instantiates IndirectList - the <JDK8 version - and ignores ClassConstants.IndirectList_Class. This means if you have a @OneToMany with an @OrderColumn on it, using any jdk8 stream methods will fail silently with no results returned.

Similar applies for CollectionMapping#useTransparentSet(), it uses JDK7 IndirectSet instead of constant from ClassConstants, so JDK 8 stream users will get a silent fail on it.

ProjectClassGenerator#addForeignReferenceMappingLines() also has some checks on IndirectMap JDK7 directly:

                    if (!collectionClassName.equals(IndirectMap.class.getName())) {
                        method.addLine(mappingName + ".useMapClass(" + collectionClassName + ".class);");
                    }

...

                    if (!collectionClassName.equals(IndirectMap.class.getName())) {
                        method.addLine(mappingName + ".useMapClass(" + collectionClassName + ".class, \"" + keyMethodName + "\");");
                    }

Should the status of this go back to being unresolved or shall I raise a new bug? This is pretty serious as where I work I had to investigate why JDK 8 stream code was giving back empty results.
Comment 13 Lukas Jungmann CLA 2015-05-17 10:34:42 EDT
(In reply to Robert Nagajek from comment #12)
> The resolution has bugs. It looks like it's present in release 2.6.0, but
> the update of Indirect* classes hasn't been replaced in all locations.

target milestone says that issue is fixed in 2.7. Are you having those issues in 2.7?
Comment 14 Robert Nagajek CLA 2015-05-17 21:10:25 EDT
OK looks like it works in 2.7. What should we do for 2.6 releases, as this particular bug was raised against 2.5 but stream support was added in 2.6, does that mean jdk 8 stream support cannot be used with eclipselink 2.6 releases or should I raise a bug against 2.6.0 to see if it will get fixed for 2.6.1? I'm happy to contribute as well if required.
Comment 15 Eclipse Webmaster CLA 2022-06-09 10:10:24 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink