diff --git a/src/main/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadata.java b/src/main/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadata.java index 18aaf8bc5..1db63e60f 100644 --- a/src/main/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadata.java +++ b/src/main/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadata.java @@ -59,7 +59,8 @@ public abstract class AbstractRepositoryMetadata implements RepositoryMetadata { return Iterable.class.isAssignableFrom(rawType) ? returnTypeInfo.getComponentType().getType() : rawType; } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.springframework.data.repository.core.RepositoryMetadata#getRepositoryInterface() */ public Class getRepositoryInterface() { diff --git a/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java b/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java index d68ddb37a..7539bc3c6 100644 --- a/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java +++ b/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java @@ -69,32 +69,24 @@ public class AnnotationRepositoryMetadata extends AbstractRepositoryMetadata { return this.domainType; } - /** - * @param repositoryInterface must not be {@literal null}. - * @return the resolved domain type, never {@literal null}. - */ private Class resolveIdType(Class repositoryInterface) { - Assert.notNull(repositoryInterface, "Repository interface must not be null!"); - RepositoryDefinition annotation = repositoryInterface.getAnnotation(RepositoryDefinition.class); - Assert.isTrue(annotation != null && annotation.idClass() != null, - String.format("Could not resolve id type of %s!", repositoryInterface)); + + if (annotation == null || annotation.idClass() == null) { + throw new IllegalArgumentException(String.format("Could not resolve id type of %s!", repositoryInterface)); + } return annotation.idClass(); } - /** - * @param repositoryInterface must not be {@literal null}. - * @return the resolved domain type, never {@literal null}. - */ private Class resolveDomainType(Class repositoryInterface) { - Assert.notNull(repositoryInterface, "Repository interface must not be null!"); - RepositoryDefinition annotation = repositoryInterface.getAnnotation(RepositoryDefinition.class); - Assert.isTrue(annotation != null && annotation.domainClass() != null, - String.format("Could not resolve domain type of %s!", repositoryInterface)); + + if (annotation == null || annotation.domainClass() == null) { + throw new IllegalArgumentException(String.format("Could not resolve domain type of %s!", repositoryInterface)); + } return annotation.domainClass(); } diff --git a/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java b/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java index 7aff93972..d6db24293 100644 --- a/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java +++ b/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java @@ -41,7 +41,7 @@ public class DefaultRepositoryMetadata extends AbstractRepositoryMetadata { /** * Creates a new {@link DefaultRepositoryMetadata} for the given repository interface. * - * @param repositoryInterface + * @param repositoryInterface must not be {@literal null}. */ public DefaultRepositoryMetadata(Class repositoryInterface) { @@ -70,33 +70,26 @@ public class DefaultRepositoryMetadata extends AbstractRepositoryMetadata { return this.idType; } - /** - * @param repositoryInterface must not be {@literal null}. - * @return the resolved domain type, never {@literal null}. - */ - private Class resolveDomainType(Class repositoryInterface) { - - Assert.notNull(repositoryInterface, "Repository interface must not be null!"); + @SuppressWarnings("unchecked") + private Class resolveIdType(Class repositoryInterface) { Class[] arguments = resolveTypeArguments(repositoryInterface, Repository.class); - Assert.isTrue(arguments != null && arguments[0] != null, - String.format("Could not resolve domain type of %s!", repositoryInterface)); - return arguments[0]; - } + if (arguments == null || arguments[1] == null) { + throw new IllegalArgumentException(String.format("Could not resolve id type of %s!", repositoryInterface)); + } - /** - * @param repositoryInterface must not be {@literal null}. - * @return the resolved id type, never {@literal null}. - */ - private Class resolveIdType(Class repositoryInterface) { + return (Class) arguments[1]; + } - Assert.notNull(repositoryInterface, "Repository interface must not be null!"); + private Class resolveDomainType(Class repositoryInterface) { Class[] arguments = resolveTypeArguments(repositoryInterface, Repository.class); - Assert.isTrue(arguments != null && arguments[1] != null, - String.format("Could not resolve id type of %s!", repositoryInterface)); - return (Class) arguments[1]; + if (arguments == null || arguments[0] == null) { + throw new IllegalArgumentException(String.format("Could not resolve domain type of %s!", repositoryInterface)); + } + + return arguments[0]; } } diff --git a/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java index ba03d5cb3..c4a2fabc8 100644 --- a/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java @@ -88,7 +88,6 @@ public class DefaultRepositoryMetadataUnitTests { public void looksUpIdClassCorrectly() throws Exception { RepositoryMetadata metadata = new DefaultRepositoryMetadata(UserRepository.class); - assertEquals(Integer.class, metadata.getIdType()); }