Community
Participate
Working Groups
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); }
I would recommend examining the collections API further for changes like this one.
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 on attachment 248006 [details] Added sort method and jUnit tests Resolve this if fixed already, pls. Thx
Created attachment 248251 [details] Final cosmetic changes
Created attachment 248252 [details] Fixed failing junits, optimized platform code
Pushed into master: http://git.eclipse.org/c/eclipselink/eclipselink.runtime.git/commit/?id=d7f0df126e68b23cbfab39ac61e1cfd53b8ad837 http://git.eclipse.org/c/eclipselink/eclipselink.runtime.git/commit/?id=ce061cf8102025c19ba38154f41fd5958dd3c215 There were some final changes missing. It's done now so closing this bug.
*** Bug 450821 has been marked as a duplicate of this bug. ***
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.
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.
Created attachment 252577 [details] patch adding all jdk8 collection methods
http://git.eclipse.org/c/eclipselink/eclipselink.runtime.git/commit/?id=8ab15a242a1cd1b5f3eded721df4ba8507132b9b
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.
(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?
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.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink