Skip to content
Browse files

Made DomainList immutable, fixes MIME4J-217

git-svn-id: https://svn.apache.org/repos/asf/james/mime4j/trunk@1390619 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 0ddf3aa commit 4d1730d067c5f688fd73a4a3f1f6220523437c10 @ieugen ieugen committed
View
15 dom/src/main/java/org/apache/james/mime4j/dom/address/DomainList.java
@@ -29,24 +29,17 @@
* An immutable, random-access list of Strings (that are supposedly domain names
* or domain literals).
*/
-public class DomainList extends AbstractList<String> implements Serializable {
+public final class DomainList extends AbstractList<String> implements Serializable {
private static final long serialVersionUID = 1L;
private final List<String> domains;
/**
- * @param domains
- * A List that contains only String objects.
- * @param dontCopy
- * true iff it is not possible for the domains list to be
- * modified by someone else.
+ * @param domains A List that contains only String objects.
*/
- public DomainList(List<String> domains, boolean dontCopy) {
- if (domains != null)
- this.domains = dontCopy ? domains : new ArrayList<String>(domains);
- else
- this.domains = Collections.emptyList();
+ public DomainList(List<String> domains) {
+ this.domains = (domains == null) ? Collections.<String>emptyList():new ArrayList<String>(domains);
}
/**
View
2 dom/src/main/java/org/apache/james/mime4j/dom/address/Mailbox.java
@@ -33,7 +33,7 @@
private static final long serialVersionUID = 1L;
private static final DomainList EMPTY_ROUTE_LIST = new DomainList(
- Collections.<String> emptyList(), true);
+ Collections.<String> emptyList());
private final String name;
private final DomainList route;
View
2 dom/src/main/java/org/apache/james/mime4j/field/address/Builder.java
@@ -164,7 +164,7 @@ private DomainList buildRoute(ASTroute node) throws ParseException {
else
throw new ParseException();
}
- return new DomainList(results, true);
+ return new DomainList(results);
}
private Mailbox buildAddrSpec(ASTaddr_spec node) {
View
2 dom/src/main/java/org/apache/james/mime4j/field/address/LenientAddressBuilder.java
@@ -124,7 +124,7 @@ DomainList parseRoute(final ByteSequence buf, final ParserCursor cursor, final B
break;
}
}
- return domains != null ? new DomainList(domains, true) : null;
+ return domains != null ? new DomainList(domains) : null;
}
private Mailbox createMailbox(
View
10 dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java
@@ -57,7 +57,7 @@ public void testNullConstructorAndBadUsage() {
public void testEmptyDomainList() {
- DomainList dl = new DomainList(null, false);
+ DomainList dl = new DomainList(null);
assertEquals(0, dl.size());
try {
@@ -77,14 +77,14 @@ public void testDomainList() {
List<String> al = new ArrayList<String>();
al.add("example.com");
- // shared arraylist
- DomainList dl = new DomainList(al, true);
+ // changing the list passed does not change DomainList's state
+ DomainList dl = new DomainList(al);
assertEquals(1, dl.size());
al.add("foo.example.com");
- assertEquals(2, dl.size());
+ assertEquals(1, dl.size());
// cloned arraylist
- DomainList dlcopy = new DomainList(al, false);
+ DomainList dlcopy = new DomainList(al);
assertEquals(2, dlcopy.size());
al.add("bar.example.com");
assertEquals(2, dlcopy.size());
View
2 dom/src/test/java/org/apache/james/mime4j/field/address/DefaultAddressFormatterTest.java
@@ -44,7 +44,7 @@ public void testGroupSerialization() {
al.add(new Mailbox("test", "example.com"));
al.add(new Mailbox("Foo!", "foo", "example.com"));
DomainList dl = new DomainList(new ArrayList<String>(
- Arrays.asList(new String[] {"foo.example.com"})), true);
+ Arrays.asList(new String[] {"foo.example.com"})));
Mailbox mailbox = new Mailbox("Foo Bar", dl, "foo2", "example.com");
assertSame(dl, mailbox.getRoute());
al.add(mailbox);

0 comments on commit 4d1730d

Please sign in to comment.
Something went wrong with that request. Please try again.