commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
Date Thu, 12 Jun 2003 01:04:12 GMT
dgraham     2003/06/11 18:04:11

  Modified:    validator/src/share/org/apache/commons/validator Field.java
  Log:
  Fixed NPE in clone().
  
  Revision  Changes    Path
  1.19      +31 -26    jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java
  
  Index: Field.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Field.java	8 Jun 2003 06:03:16 -0000	1.18
  +++ Field.java	12 Jun 2003 01:04:11 -0000	1.19
  @@ -701,32 +701,37 @@
        * Creates and returns a copy of this object.
        */
       public Object clone() {
  +        Field field = null;
           try {
  -            Field field = (Field) super.clone();
  -            
  -            field.args = new Map[this.args.length];
  -            for (int i = 0; i < this.args.length; i++) {
  -                Map argMap = new HashMap(this.args[i]);
  -                Iterator iter = argMap.keySet().iterator();
  -                while (iter.hasNext()) {
  -                    String validatorName = (String) iter.next();
  -                    Arg arg = (Arg) argMap.get(validatorName);
  -                    argMap.put(validatorName, arg.clone());
  -                }
  -                field.args[i] = argMap;
  -            }
  -
  -            field.hVars = ValidatorUtils.copyFastHashMap(hVars);
  -            field.hMsgs = ValidatorUtils.copyFastHashMap(hMsgs);
  -            field.hArg0 = ValidatorUtils.copyFastHashMap(hArg0);
  -            field.hArg1 = ValidatorUtils.copyFastHashMap(hArg1);
  -            field.hArg2 = ValidatorUtils.copyFastHashMap(hArg2);
  -            field.hArg3 = ValidatorUtils.copyFastHashMap(hArg3);
  -
  -            return field;
  +            field = (Field) super.clone();
           } catch (CloneNotSupportedException e) {
               throw new InternalError(e.toString());
           }
  +
  +        field.args = new Map[this.args.length];
  +        for (int i = 0; i < this.args.length; i++) {
  +            if (this.args[i] == null) {
  +                continue;
  +            }
  +
  +            Map argMap = new HashMap(this.args[i]);
  +            Iterator iter = argMap.keySet().iterator();
  +            while (iter.hasNext()) {
  +                String validatorName = (String) iter.next();
  +                Arg arg = (Arg) argMap.get(validatorName);
  +                argMap.put(validatorName, arg.clone());
  +            }
  +            field.args[i] = argMap;
  +        }
  +
  +        field.hVars = ValidatorUtils.copyFastHashMap(hVars);
  +        field.hMsgs = ValidatorUtils.copyFastHashMap(hMsgs);
  +        field.hArg0 = ValidatorUtils.copyFastHashMap(hArg0);
  +        field.hArg1 = ValidatorUtils.copyFastHashMap(hArg1);
  +        field.hArg2 = ValidatorUtils.copyFastHashMap(hArg2);
  +        field.hArg3 = ValidatorUtils.copyFastHashMap(hArg3);
  +
  +        return field;
       }    
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message