Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

UnsupportedOperationException is thrown inconsistently

0 views
Skip to first unread message

David Gavini

unread,
Oct 28, 2003, 1:11:56 PM10/28/03
to
Hi,

I have a multi-threaded java system (too many classes to post on this
site), and its stragely throwing an "UnsupportedOperationException".

A quick summary of what I'm doing

Class1
- contains obj

Class2
- extends class1
- funcA tries to add an obj to linkedList references as a list.
- funcB (runs from the constructor method) calls funcA
- funcC (happens to the the run() method) calls funcA

And here is the strange bit, calling funcA from FuncB has no problems.
However exactly the same function call from funcC throws the above
exception!!!

How can this be? Any ideas? Surely such exceptions are stateless
(unlike null pointer which depends on variables/system state).

Any help much appreciated, regards,
David

Lothar Kimmeringer

unread,
Oct 28, 2003, 2:09:21 PM10/28/03
to
On 28 Oct 2003 10:11:56 -0800, David Gavini wrote:

[adding object to list]

> And here is the strange bit, calling funcA from FuncB has no problems.
> However exactly the same function call from funcC throws the above
> exception!!!

The exception will be thrown by the List. The exact reason I can't
tell without seeing some code. Try to find code, that reproduces
the problem that is short enough to be posted here.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: spam...@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!

David Gavini

unread,
Oct 29, 2003, 4:51:32 AM10/29/03
to
Lothar Kimmeringer <news2...@kimmeringer.de> wrote in message news:<a4p1aevbh28q$.d...@kimmeringer.de>...

> On 28 Oct 2003 10:11:56 -0800, David Gavini wrote:
>
> [adding object to list]
>
> > And here is the strange bit, calling funcA from FuncB has no problems.
> > However exactly the same function call from funcC throws the above
> > exception!!!
>
> The exception will be thrown by the List. The exact reason I can't
> tell without seeing some code. Try to find code, that reproduces
> the problem that is short enough to be posted here.
>

This is the actual line thats throwing the error:

this.moversToday.add(mv);

where
//public List moversToday;
//this.moversToday = new LinkedList();
//mv its just a class I made.

The strange thing is that this line runs fine when called from one
function, but returns the following exception when called from another
function:

java.lang.UnsupportedOperationException
at java.util.AbstractList.add(AbstractList.java:146)
at java.util.AbstractList.add(AbstractList.java:84)
at com.dl.bls.BLSMovers.add(BLSMovers.java:61)
at com.dl.bls.BLSLists.addMovers(BLSLists.java:21)
at com.dl.bls.BLSMQ.refreshISIN(BLS.java:161)
at com.dl.bls.BLSMQ.run(BLS.java:1145)

Any clues?


>
> Regards, Lothar

VK

unread,
Oct 29, 2003, 4:55:28 AM10/29/03
to
Something's not kosher with how funcC calls funcA: evidently it asks
funcA to do something that funcB doesn't. It narrows you search pretty
well.

1. forcing serialization w/o Serializable flag set on in funcA?
2. adding a primitive to the list w/o casting it to the wrapping object?

Just guessing w/o code.

David Gavini <david....@digitallook.com> wrote in message
news:8dbc4bcc.0310...@posting.google.com...

David Gavini

unread,
Oct 29, 2003, 5:23:46 AM10/29/03
to
Lothar Kimmeringer <news2...@kimmeringer.de> wrote in message news:<a4p1aevbh28q$.d...@kimmeringer.de>...
> On 28 Oct 2003 10:11:56 -0800, David Gavini wrote:
>
> [adding object to list]
>
> > And here is the strange bit, calling funcA from FuncB has no problems.
> > However exactly the same function call from funcC throws the above
> > exception!!!
>
> The exception will be thrown by the List. The exact reason I can't
> tell without seeing some code. Try to find code, that reproduces
> the problem that is short enough to be posted here.
>
>
> Regards, Lothar

Here is a bit of code:

public class BLSMovers extends Object implements Cloneable {
public List moversToday;

public BLSMovers() {
this.moversToday = new LinkedList();
}
public void add(Mover mv) {
this.moversToday.add(mv);//this is the line that throws an exception!
}
}

Exception thrown:


java.lang.UnsupportedOperationException
at java.util.AbstractList.add(AbstractList.java:146)
at java.util.AbstractList.add(AbstractList.java:84)
at com.dl.bls.BLSMovers.add(BLSMovers.java:61)
at com.dl.bls.BLSLists.addMovers(BLSLists.java:21)
at com.dl.bls.BLSMQ.refreshISIN(BLS.java:161)
at com.dl.bls.BLSMQ.run(BLS.java:1145)

Any ideas?

Lothar Kimmeringer

unread,
Oct 29, 2003, 11:47:01 AM10/29/03
to
On 29 Oct 2003 02:23:46 -0800, David Gavini wrote:

> Here is a bit of code:
>
> public class BLSMovers extends Object implements Cloneable {
> public List moversToday;
>
> public BLSMovers() {
> this.moversToday = new LinkedList();
> }
> public void add(Mover mv) {
> this.moversToday.add(mv);//this is the line that throws an exception!
> }
> }
>
> Exception thrown:
> java.lang.UnsupportedOperationException
> at java.util.AbstractList.add(AbstractList.java:146)
> at java.util.AbstractList.add(AbstractList.java:84)
> at com.dl.bls.BLSMovers.add(BLSMovers.java:61)

Is funcC working with a cloned version of the instance of
BLSMovers? Something must be different, because the instance
of BLSMovers throwing the exception doesn't contain a
LinkedList anymore (the stacktrace goes from BLSMovers.add
to AbstractList.add immediately).

David Gavini

unread,
Oct 30, 2003, 4:33:23 AM10/30/03
to
Thanks for all your help! I have fixed the issue. It turns out that
funcC was sorting the obj. into an array and passing back a List and
not a LinkedList!!! Doh!!!! Silly programmers!!!!

Thanks again,
David

"VK" <school...@yahoo.com> wrote in message news:<3f9f8e8b$0$18533$9b62...@news.freenet.de>...

0 new messages