You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by mb...@apache.org on 2011/12/03 02:19:01 UTC
svn commit: r1209816 - in /incubator/bval/trunk: ./ bundle/
bval-core/src/main/java/org/apache/bval/
bval-core/src/main/java/org/apache/bval/model/
bval-core/src/main/java/org/apache/bval/util/
bval-guice/src/main/java/org/apache/bval/guice/ bval-jsr30...
Author: mbenson
Date: Sat Dec 3 01:19:00 2011
New Revision: 1209816
URL: http://svn.apache.org/viewvc?rev=1209816&view=rev
Log:
[BVAL-68] Use FindBugs to reduce coding errors
Added:
incubator/bval/trunk/bval-xstream/findbugs-exclude-filter.xml (with props)
Modified:
incubator/bval/trunk/bundle/pom.xml
incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/MetaBeanBuilder.java
incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/DynaTypeEnum.java
incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/FeaturesCapable.java
incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/MetaBean.java
incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/ValidationHelper.java
incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java
incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java
incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathNavigation.java
incubator/bval/trunk/bval-tck/pom.xml
incubator/bval/trunk/bval-xstream/pom.xml
incubator/bval/trunk/pom.xml
Modified: incubator/bval/trunk/bundle/pom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bundle/pom.xml?rev=1209816&r1=1209815&r2=1209816&view=diff
==============================================================================
--- incubator/bval/trunk/bundle/pom.xml (original)
+++ incubator/bval/trunk/bundle/pom.xml Sat Dec 3 01:19:00 2011
@@ -76,6 +76,13 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/MetaBeanBuilder.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/MetaBeanBuilder.java?rev=1209816&r1=1209815&r2=1209816&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/MetaBeanBuilder.java (original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/MetaBeanBuilder.java Sat Dec 3 01:19:00 2011
@@ -17,6 +17,7 @@
package org.apache.bval;
import org.apache.bval.model.MetaBean;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.ClassUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,7 +60,7 @@ public class MetaBeanBuilder {
* @return {@link MetaBeanFactory} array
*/
public MetaBeanFactory[] getFactories() {
- return factories;
+ return ArrayUtils.clone(factories);
}
/**
@@ -69,7 +70,7 @@ public class MetaBeanBuilder {
* @param factories
*/
public void setFactories(MetaBeanFactory[] factories) {
- this.factories = factories;
+ this.factories = ArrayUtils.clone(factories);
}
/**
Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/DynaTypeEnum.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/DynaTypeEnum.java?rev=1209816&r1=1209815&r2=1209816&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/DynaTypeEnum.java (original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/DynaTypeEnum.java Sat Dec 3 01:19:00 2011
@@ -16,6 +16,8 @@
*/
package org.apache.bval.model;
+import org.apache.commons.lang3.ArrayUtils;
+
/**
* Description: ("artificial" enum with custom values).<br/>
*/
@@ -82,7 +84,7 @@ public class DynaTypeEnum implements Dyn
* @return Value[]
*/
public Value[] getEnumConstants() {
- return enumConstants;
+ return ArrayUtils.clone(enumConstants);
}
/**
Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/FeaturesCapable.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/FeaturesCapable.java?rev=1209816&r1=1209815&r2=1209816&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/FeaturesCapable.java (original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/FeaturesCapable.java Sat Dec 3 01:19:00 2011
@@ -158,7 +158,7 @@ public abstract class FeaturesCapable im
* @return Validation array
*/
public Validation[] getValidations() {
- return validations;
+ return ArrayUtils.clone(validations);
}
/**
@@ -167,7 +167,7 @@ public abstract class FeaturesCapable im
* @param validations
*/
public void setValidations(Validation[] validations) {
- this.validations = validations;
+ this.validations = ArrayUtils.clone(validations);
}
/**
Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/MetaBean.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/MetaBean.java?rev=1209816&r1=1209815&r2=1209816&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/MetaBean.java (original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/MetaBean.java Sat Dec 3 01:19:00 2011
@@ -120,7 +120,7 @@ public class MetaBean extends FeaturesCa
* @return MetaProperty[]
*/
public MetaProperty[] getProperties() {
- return properties;
+ return ArrayUtils.clone(properties);
}
/**
@@ -130,8 +130,8 @@ public class MetaBean extends FeaturesCa
* the MetaProperty[] to set
*/
public void setProperties(MetaProperty[] properties) {
- Arrays.sort(properties, PropertyNameComparator.INSTANCE);
- this.properties = properties;
+ this.properties = ArrayUtils.clone(properties);
+ Arrays.sort(this.properties, PropertyNameComparator.INSTANCE);
}
/**
Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/ValidationHelper.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/ValidationHelper.java?rev=1209816&r1=1209815&r2=1209816&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/ValidationHelper.java (original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/ValidationHelper.java Sat Dec 3 01:19:00 2011
@@ -176,16 +176,16 @@ public class ValidationHelper {
final DynamicMetaBean dyn = getDynamicMetaBean(context);
context.setCurrentKey(null);
try {
- for (Object key : currentBean.keySet()) {
- context.setCurrentKey(key);
- Object value = currentBean.get(key);
+ for (Map.Entry<?, ?> entry : currentBean.entrySet()) {
+ Object value = entry.getValue();
if (value == null) {
- continue; // Null values are not validated
+ continue;
}
- if (dyn != null) {
- context.setBean(value, dyn.resolveMetaBean(value));
- } else {
+ context.setCurrentKey(entry.getKey());
+ if (dyn == null) {
context.setBean(value);
+ } else {
+ context.setBean(value, dyn.resolveMetaBean(value));
}
s.validate();
}
Modified: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java?rev=1209816&r1=1209815&r2=1209816&view=diff
==============================================================================
--- incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java (original)
+++ incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java Sat Dec 3 01:19:00 2011
@@ -80,7 +80,7 @@ public final class ValidateMethodInterce
if (!constraintViolations.isEmpty()) {
throw getException(new ConstraintViolationException(
- String.format("Validation error when calling method '%s' with arguments ",
+ String.format("Validation error when calling method '%s' with arguments %s",
method,
Arrays.deepToString(arguments)),
constraintViolations),
@@ -96,7 +96,7 @@ public final class ValidateMethodInterce
if (!constraintViolations.isEmpty()) {
throw getException(new ConstraintViolationException(
- String.format("Method '%s' returned a not valid value ",
+ String.format("Method '%s' returned a not valid value %s",
method,
returnedValue),
constraintViolations),
Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java?rev=1209816&r1=1209815&r2=1209816&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java Sat Dec 3 01:19:00 2011
@@ -24,6 +24,7 @@ import org.apache.bval.model.Validation;
import org.apache.bval.model.ValidationContext;
import org.apache.bval.model.ValidationListener;
import org.apache.bval.util.AccessStrategy;
+import org.apache.commons.lang3.ArrayUtils;
import javax.validation.ConstraintDefinitionException;
import javax.validation.ConstraintValidator;
@@ -75,7 +76,7 @@ public class ConstraintValidation<T exte
ConstraintValidator<T, ?> validator, T annotation, Class<?> owner, AccessStrategy access,
boolean reportFromComposite) {
this.attributes = new HashMap<String, Object>();
- this.validatorClasses = validatorClasses;
+ this.validatorClasses = ArrayUtils.clone(validatorClasses);
this.validator = validator;
this.annotation = annotation;
this.owner = owner;
Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathNavigation.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathNavigation.java?rev=1209816&r1=1209815&r2=1209816&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathNavigation.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathNavigation.java Sat Dec 3 01:19:00 2011
@@ -299,6 +299,29 @@ public class PathNavigation {
return null;
}
+ /**
+ * {@inheritDoc}
+ */
+ /*
+ * Override equals to make findbugs happy;
+ * would simply ignore but doesn't seem to be possible at the inner class level
+ * without attaching the filter to the containing class.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return super.equals(obj);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ /*
+ * Override hashCode to make findbugs happy in the presence of overridden #equals :P
+ */
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
}
}
Modified: incubator/bval/trunk/bval-tck/pom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-tck/pom.xml?rev=1209816&r1=1209815&r2=1209816&view=diff
==============================================================================
--- incubator/bval/trunk/bval-tck/pom.xml (original)
+++ incubator/bval/trunk/bval-tck/pom.xml Sat Dec 3 01:19:00 2011
@@ -55,6 +55,13 @@
<skip>true</skip>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
<pluginManagement>
<plugins>
Added: incubator/bval/trunk/bval-xstream/findbugs-exclude-filter.xml
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-xstream/findbugs-exclude-filter.xml?rev=1209816&view=auto
==============================================================================
--- incubator/bval/trunk/bval-xstream/findbugs-exclude-filter.xml (added)
+++ incubator/bval/trunk/bval-xstream/findbugs-exclude-filter.xml Sat Dec 3 01:19:00 2011
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!--
+ This file contains some false positive bugs detected by findbugs. Their
+ false positive nature has been analyzed individually and they have been
+ put here to instruct findbugs it must ignore them.
+-->
+<FindBugsFilter>
+ <!-- not a problem -->
+ <Match>
+ <Class name="org.apache.bval.xml.XMLMetaBeanManager" />
+ <Method name="computeRelatedMetaBean" params="org.apache.bval.model.MetaProperty,java.lang.String" returns="void" />
+ <Bug pattern="NP_LOAD_OF_KNOWN_NULL_VALUE" />
+ </Match>
+</FindBugsFilter>
Propchange: incubator/bval/trunk/bval-xstream/findbugs-exclude-filter.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/bval/trunk/bval-xstream/pom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-xstream/pom.xml?rev=1209816&r1=1209815&r2=1209816&view=diff
==============================================================================
--- incubator/bval/trunk/bval-xstream/pom.xml (original)
+++ incubator/bval/trunk/bval-xstream/pom.xml Sat Dec 3 01:19:00 2011
@@ -91,6 +91,13 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <excludeFilterFile>findbugs-exclude-filter.xml</excludeFilterFile>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
Modified: incubator/bval/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/pom.xml?rev=1209816&r1=1209815&r2=1209816&view=diff
==============================================================================
--- incubator/bval/trunk/pom.xml (original)
+++ incubator/bval/trunk/pom.xml Sat Dec 3 01:19:00 2011
@@ -562,7 +562,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>