Ensure that duplicate enums cannot be created

Bug found by Howard Lewis Ship


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137108 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2002-11-02 13:16:30 +00:00
parent b4df69ccc3
commit f44c297fa2
1 changed files with 4 additions and 1 deletions

View File

@ -115,7 +115,7 @@
* </p> * </p>
* *
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a> * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
* @version $Id: Enum.java,v 1.3 2002/10/30 21:58:18 scolebourne Exp $ * @version $Id: Enum.java,v 1.4 2002/11/02 13:16:30 scolebourne Exp $
*/ */
public abstract class Enum implements Comparable, Serializable { public abstract class Enum implements Comparable, Serializable {
/** /**
@ -164,6 +164,9 @@ protected Enum(String name) {
entry = new Entry(); entry = new Entry();
cEnumClasses.put(getClass().getName(), entry); cEnumClasses.put(getClass().getName(), entry);
} }
if (entry.map.containsKey(name)) {
throw new IllegalArgumentException("The Enum name must be unique, '" + name + "' has already been added");
}
entry.map.put(name, this); entry.map.put(name, this);
entry.list.add(this); entry.list.add(this);
} }