Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring LDAP ODM - Entry class should be declared final Warning

I have a mapped Entry ("entity") using Spring LDAP ODM. When I run unit tests with this class, I get a warning in the console upon initialization:

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

The mapped class looks like this:

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

I can't find anything relevant via Google search regarding this warning. Here's the Spring code that logs it:

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()));
    }
    ...

Any insight would be appreciated. I understand that declaring a class as final means it can't be extended, but why would Spring ODM care?

like image 506
Dmitry Sharkov Avatar asked May 17 '26 21:05

Dmitry Sharkov


1 Answers

Security reason ?

Maybe by subclassing your entity, one could store other kind of LDAP entries in the directory, leading to unforseen behavior ?

like image 192
Samuel EUSTACHI Avatar answered May 20 '26 11:05

Samuel EUSTACHI