OPENDJ-3020 Fix some AttributeDescription related NPEs
Code using an ASCIICharProp did not properly test for non-ascii characters.
Moreover, attribute options could end up referencing the whole list of options instead of its unique values.
| | |
| | | } |
| | | |
| | | cp = ASCIICharProp.valueOf(c); |
| | | if (!cp.isKeyChar(allowMalformedNamesAndOptions)) { |
| | | if (cp == null || !cp.isKeyChar(allowMalformedNamesAndOptions)) { |
| | | final LocalizableMessage message = |
| | | ERR_ATTRIBUTE_DESCRIPTION_ILLEGAL_CHARACTER.get(attributeDescription, |
| | | c, i); |
| | |
| | | } |
| | | |
| | | cp = ASCIICharProp.valueOf(c); |
| | | if (c != '.' && !cp.isDigit()) { |
| | | if (cp == null || c != '.' && !cp.isDigit()) { |
| | | final LocalizableMessage message = |
| | | ERR_ATTRIBUTE_DESCRIPTION_ILLEGAL_CHARACTER.get(attributeDescription, |
| | | c, i); |
| | |
| | | } |
| | | |
| | | cp = ASCIICharProp.valueOf(c); |
| | | if (!cp.isKeyChar(allowMalformedNamesAndOptions)) { |
| | | if (cp == null || !cp.isKeyChar(allowMalformedNamesAndOptions)) { |
| | | final LocalizableMessage message = |
| | | ERR_ATTRIBUTE_DESCRIPTION_ILLEGAL_CHARACTER.get(attributeDescription, c, i); |
| | | throw new LocalizedIllegalArgumentException(message); |
| | |
| | | } |
| | | |
| | | cp = ASCIICharProp.valueOf(c); |
| | | if (!cp.isKeyChar(allowMalformedNamesAndOptions)) { |
| | | if (cp == null || !cp.isKeyChar(allowMalformedNamesAndOptions)) { |
| | | final LocalizableMessage message = |
| | | ERR_ATTRIBUTE_DESCRIPTION_ILLEGAL_CHARACTER.get(attributeDescription, |
| | | c, i); |
| | |
| | | i = skipTrailingWhiteSpace(attributeDescription, i + 1, length); |
| | | } |
| | | |
| | | options.add(option); |
| | | normalizedOptions.add(normalizedOption); |
| | | if (normalizedOptions.add(normalizedOption)) { |
| | | options.add(option); |
| | | } |
| | | } |
| | | |
| | | return new AttributeDescription(attributeDescription, oid, attributeType, |
| | | new MultiOptionImpl(options.toArray(new String[options.size()]), |
| | | normalizedOptions.toArray(new String[normalizedOptions.size()]))); |
| | | normalizedOptions.size() > 1 |
| | | ? new MultiOptionImpl(options.toArray(new String[options.size()]), |
| | | normalizedOptions.toArray(new String[normalizedOptions.size()])) |
| | | : new SingleOptionImpl(options.get(0), normalizedOptions.first()) |
| | | ); |
| | | } |
| | | |
| | | private final String attributeDescription; |
| | |
| | | { "cn;xxx;yyy", "cn;xxx", 1, true, false }, |
| | | { "cn;xxx;yyy", "cn;xxx;yyy", 0, true, true }, |
| | | { "cn;xxx;yyy", "cn;yyy;xxx", 0, true, true }, |
| | | { "cn;a;a;a;a", "cn;a", 0, false, false}, |
| | | { "cn;a;b;a", "cn;a;b", 0, false, false}, |
| | | |
| | | { "cn", "cn;xxx;yyy", -1, false, true }, |
| | | { "cn;yyy", "cn;xxx;yyy", -1, false, true }, |
| | |
| | | { "cn;xxx;yyy;zzz", "cn", new String[] { "xxx", "yyy", "zzz" }, false }, |
| | | { "cn;zzz;YYY;xxx", "cn", new String[] { "zzz", "YYY", "xxx" }, false }, |
| | | { "CN;zzz;YYY;xxx", "CN", new String[] { "zzz", "YYY", "xxx" }, false }, |
| | | { "cn;a;a;b", "cn", new String[] { "a", "b" }, false}, |
| | | { "cn;a;a;a;a", "cn", new String[] { "a" }, false}, |
| | | }; |
| | | // @formatter:on |
| | | } |