• Post Reply Bookmark Topic Watch Topic
  • New Topic

SubList

 
Safin Ahmed
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to implement a Value List Handler
And I have this method on the Session Bean

public List getElements(int start, int end) throws CustomerException {
return customerList.subList(start,end);
}

Where customerList is of List type

When i try to call this method i get the following error
Caused by: java.lang.ClassCastException: java.util.RandomAccessSubList
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$14.write(DynamicMethodMarshallerImpl.java:338)

Any ideas?
Thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17290
9
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Funny, I don't know, but I have a guess, because it was something that I was thinking of the other day.

It sounds like a marshalling/Serialization problem. Where it might be possible that the parent class is not Serializable, or just that the class that you are returning isn't Serializable.

Instead of putting return right next to that method call. Do the method call first, then take the results and put it into a regular List. Just a suggestion.

Mark
 
Safin Ahmed
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply

If i use a Collection it works fine (but i have to code the subList method by myself) i wanted to use the List so i could use their subList function

It's strange because in the Core J2EE patterns book they use a List with a call to subList, but they use a POJO instead of a SessionBean, so i don't know if i should be using List in a EJB also
 
Thomas Taeger
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... fooled by similar naming:

RandomAccessSubList extends SubList and implements RandomAccess, but it does not extend/implement List ==> ClassCastException.



Thomas
[ March 20, 2006: Message edited by: Thomas Taeger ]
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thomas,
FYI,


SubList class extends AbstractList which inturns implements List.
 
Thomas Taeger
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dilip Kumar Jain:
SubList class extends AbstractList which inturns implements List.

Hi Dilip,
according to the googled JavaDoc
http://www.docjar.com/docs/api/java/util/RandomAccessSubList.html
you are right:


but in my local JavaDoc for "JavaTM 2 Platform Standard Ed. 5.0" (considered to be official) I just find

- the interfaces
- - List<E>
- - RandomAccess

- the classes
- - AbstractList<E>
- - Random

but nothing like java.util.SubList or util.RandomAccessSubList at all.

Problem of pre-versions?
Thomas
 
Safin Ahmed
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What strikes me as odd is that they used List.subList in such an important Book (Core J2EE Patterns)
Then why doesn't it work for me ?

They use a POJO instead of a SessionBean, but nonetheless, if it was a problem , i think someone would have noticed it by now
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thomas,

RandomAccessSubList and SubList are the inner classes of AbstractList (As of Jdk1.4). So I dont think you will be able to get their information from Official JavaDoc.

You can see AbstractList.java in the src.zip, which will give you insight how they have implemented SubList and RandomAccessSubList.
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Safin Ahmed:
I'm trying to implement a Value List Handler
And I have this method on the Session Bean

public List getElements(int start, int end) throws CustomerException {
return customerList.subList(start,end);
}

Where customerList is of List type

When i try to call this method i get the following error
Caused by: java.lang.ClassCastException: java.util.RandomAccessSubList
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$14.write(DynamicMethodMarshallerImpl.java:338)

Any ideas?
Thanks


Safin,

By Code, it looks like RandomAccessSubList, SubList and AbstractList are not marked Serializable. So you can marshall and demarshall it.

I just you to do

Since ArrayList are marked explicitly Serializable.


Hope this helps.
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Safin,

By Code, it looks like RandomAccessSubList, SubList and AbstractList are not marked Serializable. So you can marshall and demarshall it.



Sorry a lot of typographical mistakes has occurred. I meant you cant marshall and demarshall it.

I sincerely apologize for the errors.
 
Thomas Taeger
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dilip,
so if
Originally posted by Dilip Kumar Jain:

RandomAccessSubList and SubList are the inner classes ...

then the return value expected to be of any List type can not be cast to List eighther. That is where the ClassCastException came from.

Thomas
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Thomas Taeger:
Dilip,
so if

then the return value expected to be of any List type can not be cast to List eighther. That is where the ClassCastException came from.

Thomas


They are inner classes which again extends its Outer class i.e

RandomAccessSubList extends SubList and
SubList extends AbstractList

;-)
 
Safin Ahmed
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dilip thanks for your reply, it works
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!