This is the mail archive of the
java-prs@sources.redhat.com
mailing list for the Java project.
Re: java.util/372: unmodifiableList isn't unmodifiable
- To: warrenl at cygnus dot com
- Subject: Re: java.util/372: unmodifiableList isn't unmodifiable
- From: Mark Wielaard <mark at klomp dot org>
- Date: 22 Nov 2000 11:50:01 -0000
- Cc: java-prs at sourceware dot cygnus dot com,
- Reply-To: Mark Wielaard <mark at klomp dot org>
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