patrickianwilson/AbstractDataRepositories

Repository @annotation is required on interfaces but failing to provide the interface simply results in a null pointer exception during proxy

Opened this issue · 2 comments

Failing to put a @repository(EntityType.class) annotation on a repository interface results in a cryptic runtime nullpointer exception rather than helpful message.

repo steps. Create a Repository interface with no @repository annotation and then try to save an entity to that repo. Can use the InMemory impl for testing.

Just ran into this again... This is a super annoying bug.

I believe throwing a better exception from:

private Class getRepositoryInterface(Object proxy) {
        Class[] allInterfaces = proxy.getClass().getInterfaces();

        Class entityType = null;
        for (Class type: allInterfaces) {
            if (type.getAnnotation(Repository.class) != null) {
                entityType = ((Repository) type.getAnnotation(Repository.class)).value();
            }
        }

        return entityType;
    }

would probably solve this problem. Simply to a null check before returning a null entityType. Throwing a RepositoryDeclarationException is appropriate I think.