From 1aa67b085c51f71b565baece6acfc8845c024641 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 07 Jun 2016 13:52:36 +0000
Subject: [PATCH] AttributeDescription.create(attributeName, attributeType) must respect user provided attribute name
---
opendj-core/src/test/java/org/forgerock/opendj/ldap/AttributeDescriptionTestCase.java | 6 +++++-
opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java | 13 ++++++++++---
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java
index bf8b65d..da8bad0 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java
@@ -529,7 +529,14 @@
* If {@code attributeType} was {@code null}.
*/
public static AttributeDescription create(final AttributeType attributeType) {
- return create(attributeType.getNameOrOID(), attributeType);
+ Reject.ifNull(attributeType);
+
+ // Use object identity in case attribute type does not come from core schema.
+ if (attributeType == OBJECT_CLASS.getAttributeType()) {
+ return OBJECT_CLASS;
+ }
+ String attributeName = attributeType.getNameOrOID();
+ return new AttributeDescription(attributeName, attributeName, attributeType, ZERO_OPTION_IMPL);
}
/**
@@ -549,8 +556,8 @@
public static AttributeDescription create(final String attributeName, final AttributeType attributeType) {
Reject.ifNull(attributeName, attributeType);
- // Use object identity in case attribute type does not come from core schema.
- if (attributeType == OBJECT_CLASS.getAttributeType()) {
+ if (attributeType == OBJECT_CLASS.getAttributeType()
+ && attributeName.equals(attributeType.getNameOrOID())) {
return OBJECT_CLASS;
}
return new AttributeDescription(attributeName, attributeName, attributeType, ZERO_OPTION_IMPL);
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/AttributeDescriptionTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/AttributeDescriptionTestCase.java
index c6bc2b7..9783765 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/AttributeDescriptionTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/AttributeDescriptionTestCase.java
@@ -438,8 +438,12 @@
@Test
public void testCreateAttributeNameAndType() {
+ testCreateAttributeNameAndType0("CN");
+ testCreateAttributeNameAndType0("OBJECTCLASS");
+ }
+
+ private void testCreateAttributeNameAndType0(String name) {
Schema schema = Schema.getCoreSchema();
- String name = "CN";
AttributeType attributeType = schema.getAttributeType(name);
assertAttributeDescriptionCreate(
--
Gitblit v1.10.0