Skip to content

Commit 71f1592

Browse files
committed
DATACMNS-601 - Fixes for most of the SonarQube warnings.
1 parent 0f448d5 commit 71f1592

23 files changed

+93
-62
lines changed

src/main/java/org/springframework/data/auditing/AnnotationAuditingMetadata.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* @author Oliver Gierke
4040
* @since 1.5
4141
*/
42-
class AnnotationAuditingMetadata {
42+
final class AnnotationAuditingMetadata {
4343

4444
private static final AnnotationFieldFilter CREATED_BY_FILTER = new AnnotationFieldFilter(CreatedBy.class);
4545
private static final AnnotationFieldFilter CREATED_DATE_FILTER = new AnnotationFieldFilter(CreatedDate.class);

src/main/java/org/springframework/data/auditing/AuditableBeanWrapperFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void setLastModifiedDate(Calendar value) {
115115
* @author Oliver Gierke
116116
* @since 1.8
117117
*/
118-
static abstract class DateConvertingAuditableBeanWrapper implements AuditableBeanWrapper {
118+
abstract static class DateConvertingAuditableBeanWrapper implements AuditableBeanWrapper {
119119

120120
private static final boolean IS_JODA_TIME_PRESENT = ClassUtils.isPresent("org.joda.time.DateTime",
121121
ReflectionAuditingBeanWrapper.class.getClassLoader());

src/main/java/org/springframework/data/auditing/config/AuditingHandlerBeanDefinitionParser.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import org.springframework.aop.framework.ProxyFactoryBean;
2121
import org.springframework.aop.target.LazyInitTargetSource;
22-
import org.springframework.beans.factory.BeanDefinitionStoreException;
2322
import org.springframework.beans.factory.config.BeanDefinition;
2423
import org.springframework.beans.factory.support.AbstractBeanDefinition;
2524
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -110,8 +109,7 @@ protected void doParse(Element element, BeanDefinitionBuilder builder) {
110109
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#resolveId(org.w3c.dom.Element, org.springframework.beans.factory.support.AbstractBeanDefinition, org.springframework.beans.factory.xml.ParserContext)
111110
*/
112111
@Override
113-
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
114-
throws BeanDefinitionStoreException {
112+
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) {
115113

116114
this.resolvedBeanName = super.resolveId(element, definition, parserContext);
117115
return resolvedBeanName;

src/main/java/org/springframework/data/convert/CollectionFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @author Oliver Gierke
3030
*/
31-
public class CollectionFactory {
31+
public abstract class CollectionFactory {
3232

3333
private CollectionFactory() {}
3434

src/main/java/org/springframework/data/convert/SimpleTypeInformationMapper.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
public class SimpleTypeInformationMapper implements TypeInformationMapper {
3434

3535
public static final SimpleTypeInformationMapper INSTANCE = new SimpleTypeInformationMapper();
36-
private static final Map<String, ClassTypeInformation<?>> cache = new ConcurrentHashMap<String, ClassTypeInformation<?>>();
36+
private static final Map<String, ClassTypeInformation<?>> CACHE = new ConcurrentHashMap<String, ClassTypeInformation<?>>();
3737

3838
/**
3939
* Returns the {@link TypeInformation} that shall be used when the given {@link String} value is found as type hint.
@@ -56,7 +56,7 @@ public ClassTypeInformation<?> resolveTypeFrom(Object alias) {
5656
return null;
5757
}
5858

59-
ClassTypeInformation<?> information = cache.get(value);
59+
ClassTypeInformation<?> information = CACHE.get(value);
6060

6161
if (information != null) {
6262
return information;
@@ -69,7 +69,7 @@ public ClassTypeInformation<?> resolveTypeFrom(Object alias) {
6969
}
7070

7171
if (information != null) {
72-
cache.put(value, information);
72+
CACHE.put(value, information);
7373
}
7474

7575
return information;

src/main/java/org/springframework/data/domain/jaxb/SpringDataJaxb.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@
4444
*
4545
* @author Oliver Gierke
4646
*/
47-
public class SpringDataJaxb {
47+
public abstract class SpringDataJaxb {
4848

4949
public static final String NAMESPACE = "http://www.springframework.org/schema/data/jaxb";
5050

51+
private SpringDataJaxb() {}
52+
5153
/**
5254
* The DTO for {@link Pageable}s/{@link PageRequest}s.
5355
*

src/main/java/org/springframework/data/geo/GeoPage.java

+30
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.springframework.data.domain.Page;
1919
import org.springframework.data.domain.PageImpl;
2020
import org.springframework.data.domain.Pageable;
21+
import org.springframework.util.ObjectUtils;
2122

2223
/**
2324
* Custom {@link Page} to carry the average distance retrieved from the {@link GeoResults} the {@link GeoPage} is set up
@@ -66,4 +67,33 @@ public GeoPage(GeoResults<T> results, Pageable pageable, long total) {
6667
public Distance getAverageDistance() {
6768
return averageDistance;
6869
}
70+
71+
/*
72+
* (non-Javadoc)
73+
* @see org.springframework.data.domain.PageImpl#equals(java.lang.Object)
74+
*/
75+
@Override
76+
public boolean equals(Object obj) {
77+
78+
if (this == obj) {
79+
return true;
80+
}
81+
82+
if (!(obj instanceof GeoPage)) {
83+
return false;
84+
}
85+
86+
GeoPage<?> that = (GeoPage<?>) obj;
87+
88+
return super.equals(obj) && ObjectUtils.nullSafeEquals(this.averageDistance, that.averageDistance);
89+
}
90+
91+
/*
92+
* (non-Javadoc)
93+
* @see org.springframework.data.domain.PageImpl#hashCode()
94+
*/
95+
@Override
96+
public int hashCode() {
97+
return super.hashCode() + ObjectUtils.nullSafeHashCode(this.averageDistance);
98+
}
6999
}

src/main/java/org/springframework/data/mapping/PropertyPath.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ public class PropertyPath implements Iterable<PropertyPath> {
6969
Assert.notNull(owningType);
7070

7171
String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name);
72-
TypeInformation<?> type = owningType.getProperty(propertyName);
72+
TypeInformation<?> propertyType = owningType.getProperty(propertyName);
7373

74-
if (type == null) {
74+
if (propertyType == null) {
7575
throw new PropertyReferenceException(propertyName, owningType, base);
7676
}
7777

7878
this.owningType = owningType;
79-
this.isCollection = type.isCollectionLike();
80-
this.type = type.getActualType();
79+
this.isCollection = propertyType.isCollectionLike();
80+
this.type = propertyType.getActualType();
8181
this.name = propertyName;
8282
}
8383

src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,18 @@ public PersistentPropertyPath<T> getExtensionForBaseOf(PersistentPropertyPath<T>
158158
return this;
159159
}
160160

161-
List<T> properties = new ArrayList<T>();
161+
List<T> result = new ArrayList<T>();
162162
Iterator<T> iterator = iterator();
163163

164164
for (int i = 0; i < base.getLength(); i++) {
165165
iterator.next();
166166
}
167167

168168
while (iterator.hasNext()) {
169-
properties.add(iterator.next());
169+
result.add(iterator.next());
170170
}
171171

172-
return new DefaultPersistentPropertyPath<T>(properties);
172+
return new DefaultPersistentPropertyPath<T>(result);
173173
}
174174

175175
/*

src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ public String getSpelExpression() {
156156
@Override
157157
public boolean isTransient() {
158158

159-
if (isTransient == null) {
160-
boolean isTransient = super.isTransient() || isAnnotationPresent(Transient.class);
161-
this.isTransient = isTransient || isAnnotationPresent(Value.class) || isAnnotationPresent(Autowired.class);
159+
if (this.isTransient == null) {
160+
boolean potentiallyTransient = super.isTransient() || isAnnotationPresent(Transient.class);
161+
this.isTransient = potentiallyTransient || isAnnotationPresent(Value.class)
162+
|| isAnnotationPresent(Autowired.class);
162163
}
163164

164165
return this.isTransient;

src/main/java/org/springframework/data/querydsl/QueryDslPredicateExecutor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.querydsl;
1717

18-
import org.springframework.dao.IncorrectResultSizeDataAccessException;
1918
import org.springframework.data.domain.Page;
2019
import org.springframework.data.domain.Pageable;
2120

@@ -35,7 +34,8 @@ public interface QueryDslPredicateExecutor<T> {
3534
*
3635
* @param predicate
3736
* @return a single entity matching the given {@link Predicate} or {@literal null} if none was found.
38-
* @throws IncorrectResultSizeDataAccessException if the predicate yields more than one result.
37+
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the predicate yields more than one
38+
* result.
3939
*/
4040
T findOne(Predicate predicate);
4141

src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class RepositoryConfigurationDelegate {
4949
private final RepositoryConfigurationSource configurationSource;
5050
private final ResourceLoader resourceLoader;
5151
private final Environment environment;
52-
private final BeanNameGenerator generator;
52+
private final BeanNameGenerator beanNameGenerator;
5353
private final boolean isXml;
5454

5555
/**
@@ -87,7 +87,7 @@ public RepositoryConfigurationDelegate(RepositoryConfigurationSource configurati
8787
RepositoryBeanNameGenerator generator = new RepositoryBeanNameGenerator();
8888
generator.setBeanClassLoader(resourceLoader.getClassLoader());
8989

90-
this.generator = generator;
90+
this.beanNameGenerator = generator;
9191
this.configurationSource = configurationSource;
9292
this.resourceLoader = resourceLoader;
9393
this.environment = defaultEnvironment(environment, resourceLoader);
@@ -143,7 +143,7 @@ public List<BeanComponentDefinition> registerRepositoriesIn(BeanDefinitionRegist
143143
}
144144

145145
AbstractBeanDefinition beanDefinition = definitionBuilder.getBeanDefinition();
146-
String beanName = generator.generateBeanName(beanDefinition, registry);
146+
String beanName = beanNameGenerator.generateBeanName(beanDefinition, registry);
147147

148148
if (LOGGER.isDebugEnabled()) {
149149
LOGGER.debug("Registering repository: " + beanName + " - Interface: " + configuration.getRepositoryInterface()

src/main/java/org/springframework/data/repository/core/support/PersistentEntityInformation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* {@link EntityInformation} implementation that uses a {@link PersistentEntity} to obtain id type information and uses
26-
* a {@link BeanWrapper} to access the property value if requested.
26+
* a {@link org.springframework.data.mapping.IdentifierAccessor} to access the property value if requested.
2727
*
2828
* @author Oliver Gierke
2929
*/

src/main/java/org/springframework/data/repository/query/Parameters.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public T getBindableParameter(int bindableIndex) {
255255
*
256256
* @param method
257257
*/
258-
private void assertEitherAllParamAnnotatedOrNone() {
258+
private final void assertEitherAllParamAnnotatedOrNone() {
259259

260260
boolean nameFound = false;
261261
int index = 0;

src/main/java/org/springframework/data/repository/query/QueryMethod.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ public Class<?> getJavaType() {
119119
* @return
120120
*/
121121
public String getNamedQueryName() {
122-
123-
Class<?> domainClass = getDomainClass();
124-
return String.format("%s.%s", domainClass.getSimpleName(), method.getName());
122+
return String.format("%s.%s", getDomainClass().getSimpleName(), method.getName());
125123
}
126124

127125
/**
@@ -181,7 +179,7 @@ public boolean isSliceQuery() {
181179
*
182180
* @return
183181
*/
184-
public boolean isPageQuery() {
182+
public final boolean isPageQuery() {
185183

186184
Class<?> returnType = method.getReturnType();
187185
return org.springframework.util.ClassUtils.isAssignable(Page.class, returnType);

src/main/java/org/springframework/data/repository/support/Repositories.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
public class Repositories implements Iterable<Class<?>> {
4646

4747
static final Repositories NONE = new Repositories();
48+
4849
private static final RepositoryFactoryInformation<Object, Serializable> EMPTY_REPOSITORY_FACTORY_INFO = EmptyRepositoryFactoryInformation.INSTANCE;
50+
private static final String DOMAIN_TYPE_MUST_NOT_BE_NULL = "Domain type must not be null!";
4951

5052
private final BeanFactory beanFactory;
5153
private final Map<Class<?>, String> repositoryBeanNames;
@@ -102,7 +104,7 @@ private void populateRepositoryFactoryInformation(ListableBeanFactory factory) {
102104
*/
103105
public boolean hasRepositoryFor(Class<?> domainClass) {
104106

105-
Assert.notNull(domainClass, "Domain class must not be null!");
107+
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
106108

107109
return repositoryFactoryInfos.containsKey(domainClass);
108110
}
@@ -115,7 +117,7 @@ public boolean hasRepositoryFor(Class<?> domainClass) {
115117
*/
116118
public Object getRepositoryFor(Class<?> domainClass) {
117119

118-
Assert.notNull(domainClass, "Domain class must not be null!");
120+
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
119121

120122
String repositoryBeanName = repositoryBeanNames.get(domainClass);
121123
return repositoryBeanName == null || beanFactory == null ? null : beanFactory.getBean(repositoryBeanName);
@@ -131,7 +133,7 @@ public Object getRepositoryFor(Class<?> domainClass) {
131133
*/
132134
private RepositoryFactoryInformation<Object, Serializable> getRepositoryFactoryInfoFor(Class<?> domainClass) {
133135

134-
Assert.notNull(domainClass, "Domain class must not be null!");
136+
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
135137

136138
RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos.get(ClassUtils
137139
.getUserClass(domainClass));
@@ -147,7 +149,7 @@ private RepositoryFactoryInformation<Object, Serializable> getRepositoryFactoryI
147149
@SuppressWarnings("unchecked")
148150
public <T, S extends Serializable> EntityInformation<T, S> getEntityInformationFor(Class<?> domainClass) {
149151

150-
Assert.notNull(domainClass, "Domain class must not be null!");
152+
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
151153

152154
return (EntityInformation<T, S>) getRepositoryFactoryInfoFor(domainClass).getEntityInformation();
153155
}
@@ -161,7 +163,7 @@ public <T, S extends Serializable> EntityInformation<T, S> getEntityInformationF
161163
*/
162164
public RepositoryInformation getRepositoryInformationFor(Class<?> domainClass) {
163165

164-
Assert.notNull(domainClass, "Domain class must not be null!");
166+
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
165167

166168
RepositoryFactoryInformation<Object, Serializable> information = getRepositoryFactoryInfoFor(domainClass);
167169
return information == EMPTY_REPOSITORY_FACTORY_INFO ? null : information.getRepositoryInformation();
@@ -177,7 +179,7 @@ public RepositoryInformation getRepositoryInformationFor(Class<?> domainClass) {
177179
*/
178180
public PersistentEntity<?, ?> getPersistentEntity(Class<?> domainClass) {
179181

180-
Assert.notNull(domainClass, "Domain class must not be null!");
182+
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
181183
return getRepositoryFactoryInfoFor(domainClass).getPersistentEntity();
182184
}
183185

@@ -189,7 +191,7 @@ public RepositoryInformation getRepositoryInformationFor(Class<?> domainClass) {
189191
*/
190192
public List<QueryMethod> getQueryMethodsFor(Class<?> domainClass) {
191193

192-
Assert.notNull(domainClass, "Domain class must not be null!");
194+
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
193195
return getRepositoryFactoryInfoFor(domainClass).getQueryMethods();
194196
}
195197

src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
* @author Oliver Gierke
3939
* @since 1.8
4040
*/
41-
public class QueryExecutionConverters {
41+
public abstract class QueryExecutionConverters {
4242

4343
private static final boolean GUAVA_PRESENT = ClassUtils.isPresent("com.google.common.base.Optional",
4444
QueryExecutionConverters.class.getClassLoader());
4545
private static final boolean JDK_PRESENT = ClassUtils.isPresent("java.util.Optional",
4646
QueryExecutionConverters.class.getClassLoader());
4747

48-
private static Set<Class<?>> WRAPPER_TYPES = new HashSet<Class<?>>();
48+
private static final Set<Class<?>> WRAPPER_TYPES = new HashSet<Class<?>>();
4949

5050
static {
5151

src/main/java/org/springframework/data/util/AnnotationDetectionMethodCallback.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess
9494
return;
9595
}
9696

97-
A annotation = AnnotationUtils.findAnnotation(method, annotationType);
97+
A foundAnnotation = AnnotationUtils.findAnnotation(method, annotationType);
9898

99-
if (annotation != null) {
99+
if (foundAnnotation != null) {
100100

101101
if (foundMethod != null && enforceUniqueness) {
102-
throw new IllegalStateException(String.format(MULTIPLE_FOUND, annotation.getClass().getName(), foundMethod,
102+
throw new IllegalStateException(String.format(MULTIPLE_FOUND, foundAnnotation.getClass().getName(), foundMethod,
103103
method));
104104
}
105105

106-
this.annotation = annotation;
106+
this.annotation = foundAnnotation;
107107
this.foundMethod = method;
108108
}
109109
}

src/main/java/org/springframework/data/util/DirectFieldAccessFallbackBeanWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void setPropertyValue(String propertyName, Object value) {
7777

7878
if (field == null) {
7979
throw new NotWritablePropertyException(getWrappedClass(), propertyName,
80-
"Could not find field for property during fallback access!");
80+
"Could not find field for property during fallback access!", e);
8181
}
8282

8383
makeAccessible(field);

0 commit comments

Comments
 (0)