java.util/372: unmodifiableList isn't unmodifiable
Mark Wielaard
mark@klomp.org
Wed Nov 22 03:50:00 GMT 2000
The following reply was made to PR java.util/372; it has been noted by GNATS.
From: Mark Wielaard <mark@klomp.org>
To: bryce@albatross.co.nz
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: java.util/372: unmodifiableList isn't unmodifiable
Date: Wed, 22 Nov 2000 12:43:35 +0100
Hi,
On Wed, Nov 22, 2000 at 10:11:42AM -0000, bryce@albatross.co.nz wrote:
>
> >Description:
> Collections.UnModifiableList appears to be implemented
> incorrectly. Refer to the test case.
> >How-To-Repeat:
> import java.util.*;
>
> public class Unmodifiable
> {
> public static void main(String[] args)
> {
> List l = new ArrayList();
> l.add("foo");
> l = Collections.unmodifiableList(l);
> System.out.println (l); // should print contents of list
> l.set(0, "bar"); // should throw exception
> }
> }
You are cheating :) java.util.Collections is not (yet) in libgcj
but I assume you mean the implementation of Collections in Classpath.
Your observation is correct. The innerclass UnmodifiableCollection
in Collections should implement toString() (and probably hashCode()
and equals() which are now implemented by all the subclasses)
some of the methods of UnmodifiableList methods should throw exceptions
instead of just passing them to the wrapped list object.
(add(), addAll(), remove() and set())
Cheers,
Mark
More information about the Java-prs
mailing list