Error message I can't figure out

T

Tim Slattery

I'm running a J2EE app in Weblogic. The app works, but I keep getting
this error on the console:

java.rmi.MarshalException: failed to marshal
update(Lweblogic.cluster.replication.ROID;ILjava.io.Serializable;Ljava.lang.Object;);
nested exception is:
java.io.NotSerializableException: java.util.TreeMap$Values

I am storing a TreeMap object in the session object, but the
description of TreeMap says that it implements the Serializable
interface. So why am I getting this error?
 
D

Daniel Pitts

I'm running a J2EE app in Weblogic. The app works, but I keep getting
this error on the console:

java.rmi.MarshalException: failed to marshal
update(Lweblogic.cluster.replication.ROID;ILjava.io.Serializable;Ljava.lang.Object;);
nested exception is:
java.io.NotSerializableException: java.util.TreeMap$Values

I am storing a TreeMap object in the session object, but the
description of TreeMap says that it implements the Serializable
interface. So why am I getting this error?
The only thing I could think of is if the keys or values of your map
aren't Serializable.

Actually, hmm... I'm not seeing a "Values" class in the TreeMap source
code. At least not in 1.5. Let me double check 1.6...


Ah, I see it in 1.6

The collection returned from TreeMap.values() is not Serializable. You
either need to serialize the whole TreeMap, or copy the values into a
different container.
 
R

Roedy Green

nested exception is:
java.io.NotSerializableException: java.util.TreeMap$Values

I am storing a TreeMap object in the session object, but the
description of TreeMap says that it implements the Serializable
interface. So why am I getting this error?

see
http://mindprod.com/jgloss/runerrormessages.html#NOTSERIALIAZABLEEXCEPTION

Not only does TreeMap have to be serializable, but also the keys and
objects you store in it, and the objects those objects point to etc.

values refers to the Collection inside TreeMap of the values ( the
things you look up by key), in other words your objects.
 
M

Mike Schilling

Roedy Green said:
see
http://mindprod.com/jgloss/runerrormessages.html#NOTSERIALIAZABLEEXCEPTION

Not only does TreeMap have to be serializable, but also the keys and
objects you store in it, and the objects those objects point to etc.

values refers to the Collection inside TreeMap of the values ( the
things you look up by key), in other words your objects.

TreeMap$Values is an inner class, the type of the object returned from
TreeMap.values(). It's not used for anything else. In particular, it's not
involved when serializing a TreeMap. It's also not serializable. The only
way to get this error is to attempt to serialize the return from
TreeMap.values(). This will always fail, regardless of the types of the
objects in the map; in fact, it will fail even if the map is empty.
 
R

Roedy Green

TreeMap$Values is an inner class, the type of the object returned from
TreeMap.values(). It's not used for anything else. In particular, it's not
involved when serializing a TreeMap. It's also not serializable. The only
way to get this error is to attempt to serialize the return from
TreeMap.values(). This will always fail, regardless of the types of the
objects in the map; in fact, it will fail even if the map is empty.

I would call that a bug.

Could Sun fix it just by adding an "implements Serializable" to the
Values nested class?


TreeMap.Values is a private static nested class of TreeMap that
extends AbstractCollection<V>.

--
Roedy Green Canadian Mind Products
http://mindprod.com

The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair.
~ Douglas Adams (born: 1952-03-11 died: 2001-05-11 at age: 49)
 
R

Roedy Green

TreeMap$Values is an inner class, the type of the object returned from
TreeMap.values(). It's not used for anything else. In particular, it's not
involved when serializing a TreeMap. It's also not serializable. The only
way to get this error is to attempt to serialize the return from
TreeMap.values(). This will always fail, regardless of the types of the
objects in the map; in fact, it will fail even if the map is empty.


For now, he will have to convert the result to an ordinary array which
can be serialized. See the sample code at
http://mindprod.com/jgloss/treemap.html
--
Roedy Green Canadian Mind Products
http://mindprod.com

The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair.
~ Douglas Adams (born: 1952-03-11 died: 2001-05-11 at age: 49)
 
J

Joshua Cranmer

Could Sun fix it just by adding an "implements Serializable" to the
Values nested class?

The value set class (and those for the key and entry sets, FWIW) is
defined as an inner class. Therefore, all of its constructors implicitly
have an argument of TreeMap, which makes making the Serializable a
little more problematic. Sun even gives the following warning:
Note - Serialization of inner classes (i.e., nested classes that are not
static member classes), including local and anonymous classes, is
strongly discouraged for several reasons.

As to why this was done, I cannot say for certain. The sub map return
stuff is serializable on the other hand, which leads me to believe that
the developers of Java decided that the value, key, and entry sets are
merely views into the data of a TreeMap and should not live on their own
while submaps of a TreeMap are full-fledged maps in their own rights and
should be able to be divorced from the original.
 
R

Roedy Green

The value set class (and those for the key and entry sets, FWIW) is
defined as an inner class. Therefore, all of its constructors implicitly
have an argument of TreeMap, which makes making the Serializable a
little more problematic.

It is a STATIC nested class, so you don't have THAT complication.
--
Roedy Green Canadian Mind Products
http://mindprod.com

The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair.
~ Douglas Adams (born: 1952-03-11 died: 2001-05-11 at age: 49)
 
J

Joshua Cranmer

It is a STATIC nested class, so you don't have THAT complication.

Not according to my installation:
$ javap -private java.util.TreeMap\$Values
Compiled from "TreeMap.java"
class java.util.TreeMap$Values extends java.util.AbstractCollection{
final java.util.TreeMap this$0;
[ The signature of a non-static class ]

Or, if you want the source code itself:
class Values extends AbstractCollection<V> {

I don't see no static there :)
 
M

Mike Schilling

Joshua said:
It is a STATIC nested class, so you don't have THAT complication.

Not according to my installation:
$ javap -private java.util.TreeMap\$Values
Compiled from "TreeMap.java"
class java.util.TreeMap$Values extends java.util.AbstractCollection{
final java.util.TreeMap this$0;
[ The signature of a non-static class ]

Or, if you want the source code itself:
class Values extends AbstractCollection<V> {

I don't see no static there :)

Since it's purpose is to be a view into a TreeMap, it would either need to
be a non-static class of have a field of type TreeMap that pointed to its
parent. [1]. Also, since its purpose is to be a view into a TreeMap, it
would be a weird thing to serialize: If it were deserialized without its
parent TreeMap, what good would it be? And if you're going to deserialize
the TreeMap, you can just call values() on that .




1. Not that large a distinction, obviously.
 
L

Lew

Joshua Cranmer wrote, quoted or indirectly quoted someone who said :

Roedy said:
It is a STATIC nested class, so you don't have THAT complication.

Well, you sort of do, in that the 'values()' set is backed by the Map and
changes to each affect the other. You don't have a 'values()' set instance
unless you have the Map instance.
 
R

Roedy Green

Since it's purpose is to be a view into a TreeMap, it would either need to
be a non-static class of have a field of type TreeMap that pointed to its
parent. [1]. Also, since its purpose is to be a view into a TreeMap, it
would be a weird thing to serialize: If it were deserialized without its
parent TreeMap, what good would it be? And if you're going to deserialize
the TreeMap, you can just call values() on that

If you could make changes to the extracted list that reflect back on
the original collection, serializing would be pretty weird.

TreeMap.KeySet is a static class
static final class KeySet<E> extends AbstractSet<E> implements
NavigableSet<E>

oddly TreeMap.Values is NOT.
class Values extends AbstractCollection<V>
--
Roedy Green Canadian Mind Products
http://mindprod.com

The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair.
~ Douglas Adams (born: 1952-03-11 died: 2001-05-11 at age: 49)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top