[
https://issues.apache.org/jira/browse/OPENJPA-1025?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12701067#action_12701067
]
Julien Kronegg commented on OPENJPA-1025:
-----------------------------------------
I'm not sure about the patch content for AbstractNonSequentialResultList (
https://issues.apache.org/jira/secure/attachment/12405947/OPENJPA-1025.patch ).
In this class, the workaround "new ArrayList()" is used.
The List.subList(int,int) contract is to provide a view on the original list,
not a shallow copy (see "Range-View Operation" section in
http://java.sun.com/docs/books/tutorial/collections/interfaces/list.html ).
Thus, operations on the subList are in fact done on the original List.
Let's try with the following code:
myAbstractNonSequentialResultList.subList(first, last).add(myElement);
If the AbstractNonSequentialResultList class implements the List.subList
contract correctly, this should raise an exception because the underlying
AbstractResultList is read only (this is the expected result). But with the
patch, the above code works correctly and the programmer may think that the
underlying List has been modified, while it has still the same number of
elements.
So IMHO, the patch is correct, except for class AbstractNonSequentialResultList
which should use a true view of the original List and not a shallow copy. For
this class, I see 3 solutions:
1) the subList method return a true *view* of the original List and not a
shallow copy: this would be the best solution (See java.util.AbstractList for
an implementation)
2) the subList method throws a "not implemented exception": this would be a
quickfix (I'm not sure it would solve the issue)
3) the subList method return a shallow copy of the original List (i.e. new
ArrayList()): this solution is not desirable because it does not respect the
List.subList contract as described above.
> AbstractResultList.subList throws UnsupportedOperationException
> ---------------------------------------------------------------
>
> Key: OPENJPA-1025
> URL: https://issues.apache.org/jira/browse/OPENJPA-1025
> Project: OpenJPA
> Issue Type: Bug
> Components: lib
> Affects Versions: 1.2.1, 1.3.0, 2.0.0
> Environment:
> http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java?revision=757278&view=markup,
> Seam 2.0, OpenJPA 1.2.1
> Reporter: Julien Kronegg
> Attachments: OPENJPA-1025.patch
>
> Original Estimate: 4h
> Remaining Estimate: 4h
>
> AbstractResultList implements the basics for readonly result lists. When
> calling the subList(int,int) method, the following exception is raised:
> java.lang.UnsupportedOperationException
> at
> org.apache.openjpa.lib.rop.AbstractResultList.subList(AbstractResultList.java:84)
> at
> org.apache.openjpa.kernel.DelegatingResultList.subList(DelegatingResultList.java:308)
> ...
> Since the subList() method contract is to create a new List from the
> ResultList, this operation does not modify the original list: it only
> provides a *view* on the original list (see
> http://java.sun.com/docs/books/tutorial/collections/interfaces/list.html ).
> This problem is also found by other users:
> http://n2.nabble.com/DelegatingResultList.subList-not-implemented--td210389.html
> They found the (bad) workaround to build a new List (bad because this is not
> the same as calling subList()):
> List mySubList = new ArrayList(openjpaList).subList(from, to);
> The AbstractResultList class should be modified by one of this solution
> (sorted by decreasing preference order):
> 1) the AbstractResultList class should extends java.util.AbstractList and the
> subList() method should be removed (because implemented by AbstractList)
> 2) the subList() method should be implemented to return a view on the
> original list. See java.util.AbstractList for an implementation
> (http://www.koders.com/java/fidCFCB47A1819AB345234CC04B6A1EA7554C2C17C0.aspx?s=iso+3166
> )
> 3) the subList() method should throw the exception with the message "this
> method is not yet implemented. Workaround: new
> ArrayList(openjpaList).subList(from, to)"
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.