3

我有一个Entry使用 Spring LDAP ODM 的映射(“实体”)。当我使用这个类运行单元测试时,我会在初始化时在控制台中收到警告:

Mar 9, 2012 2:32:40 PM org.springframework.ldap.odm.core.impl.ObjectMetaData <init>
WARNING: The Entry class Superhero should be declared final

映射的类如下所示:

@Entry(objectClasses = {"batman", "superman", "spiderman", "dontworryaboutthese"})
public class Superhero {
    @Id
    @JsonIgnore
    private Name dn;
    ...

我无法通过 Google 搜索找到与此警告相关的任何内容。这是记录它的 Spring 代码:

public ObjectMetaData(Class<?> clazz) {
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Extracting metadata from %1$s", clazz));
    }

    // Get object class metadata - the @Entity annotation
    Entry entity = (Entry)clazz.getAnnotation(Entry.class);
    if (entity != null) {
        // Default objectclass name to the class name unless it's specified
        // in @Entity(name={objectclass1, objectclass2});
        String[] localObjectClasses = entity.objectClasses();
        if (localObjectClasses != null && localObjectClasses.length > 0 && localObjectClasses[0].length() > 0) {
            for (String localObjectClass:localObjectClasses) {
                objectClasses.add(new CaseIgnoreString(localObjectClass));
            }
        } else {
            objectClasses.add(new CaseIgnoreString(clazz.getSimpleName()));
        }
    } else {
        throw new MetaDataException(String.format("Class %1$s must have a class level %2$s annotation", clazz,
                Entry.class));
    }

    // Check the class is final
    if (!Modifier.isFinal(clazz.getModifiers())) {
        LOG.warn(String.format("The Entry class %1$s should be declared final", clazz.getSimpleName()));
    }
    ...

任何见解将不胜感激。我知道将一个类声明为 final 意味着它不能被扩展,但是 Spring ODM 为什么会关心呢?

4

1 回答 1

1

安全原因?

也许通过子类化您的实体,可以在目录中存储其他类型的 LDAP 条目,从而导致不可预见的行为?

于 2012-04-18T12:16:52.060 回答