Changeset 6d6f7fb


Ignore:
Timestamp:
Nov 28, 2014 1:45:33 PM (7 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
1773fc0
Parents:
449ce31
Message:

Data: Disallow duplicate keys in a Mapping

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/DataHelper.java

    r449ce31 r6d6f7fb  
    109109     * is repeated until there are no more bytes (not characters!) left as defined by the
    110110     * first two byte integer.
     111     *
     112     *  As of 0.9.18, throws DataFormatException on duplicate key
     113     *
    111114     * @param rawStream stream to read the mapping from
    112115     * @throws DataFormatException if the format is invalid
     
    123126    /**
    124127     *  Ditto, load into an existing properties
     128     *
     129     *  As of 0.9.18, throws DataFormatException on duplicate key
     130     *
    125131     *  @param props the Properties to load into
     132     *  @param rawStream stream to read the mapping from
     133     *  @throws DataFormatException if the format is invalid
     134     *  @throws IOException if there is a problem reading the data
     135     *  @return the parameter props
    126136     *  @since 0.8.13
    127137     */
     
    149159                throw new DataFormatException("Bad value");
    150160            }
    151             props.put(key, val);
     161            Object old = props.put(key, val);
     162            if (old != null)
     163                throw new DataFormatException("Duplicate key " + key);
    152164        }
    153165        return props;
     
    300312     * Strings must be UTF-8 encoded in the byte array.
    301313     *
     314     *  As of 0.9.18, throws DataFormatException on duplicate key
     315     *
    302316     * @param source source
    303317     * @param target returned Properties
     
    334348                throw new DataFormatException("Bad value", ioe);
    335349            }
    336             target.put(key, val);
     350            Object old= target.put(key, val);
     351            if (old != null)
     352                throw new DataFormatException("Duplicate key " + key);
    337353        }
    338354        return offset + size;
     
    399415     *
    400416     * As of 0.9.10, an empty value is allowed.
     417     *
     418     * As in Java Properties, duplicate keys are allowed, last one wins.
     419     *
    401420     */
    402421    public static void loadProps(Properties props, File file) throws IOException {
Note: See TracChangeset for help on using the changeset viewer.