You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/06/14 00:40:45 UTC
[commons-lang] branch master updated: Better way to deal with ignored exceptions and PMD checks.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new bdde0e1c1 Better way to deal with ignored exceptions and PMD checks.
new bd7956949 Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-lang.git
bdde0e1c1 is described below
commit bdde0e1c13ed5dddcb358ef8b3d0c0dce11d8b92
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jun 13 20:40:11 2022 -0400
Better way to deal with ignored exceptions and PMD checks.
Gets rid of output like:
<suppressedviolation
filename="...\src\main\java\org\apache\commons\lang3\reflect\MemberUtils.java"
suppressiontype="nopmd" msg="Avoid empty catch blocks" usermsg="
"></suppressedviolation>
---
src/main/java/org/apache/commons/lang3/ClassUtils.java | 2 +-
.../java/org/apache/commons/lang3/math/NumberUtils.java | 14 +++++++-------
.../org/apache/commons/lang3/reflect/ConstructorUtils.java | 3 ++-
.../java/org/apache/commons/lang3/reflect/FieldUtils.java | 6 +++---
.../java/org/apache/commons/lang3/reflect/MemberUtils.java | 2 +-
.../java/org/apache/commons/lang3/reflect/MethodUtils.java | 5 +++--
.../apache/commons/lang3/text/ExtendedMessageFormat.java | 2 +-
7 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java b/src/main/java/org/apache/commons/lang3/ClassUtils.java
index bdd6e9ef1..a8ede1e56 100644
--- a/src/main/java/org/apache/commons/lang3/ClassUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java
@@ -567,7 +567,7 @@ public class ClassUtils {
try {
return getClass(classLoader, className.substring(0, lastDotIndex) + INNER_CLASS_SEPARATOR_CHAR + className.substring(lastDotIndex + 1),
initialize);
- } catch (final ClassNotFoundException ex2) { // NOPMD
+ } catch (final ClassNotFoundException ignored) {
// ignore exception
}
}
diff --git a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
index a44c59cf5..ae6b87928 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -743,7 +743,7 @@ public class NumberUtils {
&& (!numeric.isEmpty() && numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) {
try {
return createLong(numeric);
- } catch (final NumberFormatException nfe) { // NOPMD
+ } catch (final NumberFormatException ignored) {
// Too big for a long
}
return createBigInteger(numeric);
@@ -760,7 +760,7 @@ public class NumberUtils {
return f;
}
- } catch (final NumberFormatException nfe) { // NOPMD
+ } catch (final NumberFormatException ignored) {
// ignore the bad number
}
//$FALL-THROUGH$
@@ -771,12 +771,12 @@ public class NumberUtils {
if (!(d.isInfinite() || d.doubleValue() == 0.0D && !isZero(mant, dec))) {
return d;
}
- } catch (final NumberFormatException nfe) { // NOPMD
+ } catch (final NumberFormatException ignored) {
// ignore the bad number
}
try {
return createBigDecimal(numeric);
- } catch (final NumberFormatException e) { // NOPMD
+ } catch (final NumberFormatException ignored) {
// ignore the bad number
}
//$FALL-THROUGH$
@@ -796,12 +796,12 @@ public class NumberUtils {
//Must be an Integer, Long, Biginteger
try {
return createInteger(str);
- } catch (final NumberFormatException nfe) { // NOPMD
+ } catch (final NumberFormatException ignored) {
// ignore the bad number
}
try {
return createLong(str);
- } catch (final NumberFormatException nfe) { // NOPMD
+ } catch (final NumberFormatException ignored) {
// ignore the bad number
}
return createBigInteger(str);
@@ -823,7 +823,7 @@ public class NumberUtils {
}
return b;
}
- } catch (final NumberFormatException nfe) { // NOPMD
+ } catch (final NumberFormatException ignored) {
// ignore the bad number
}
return createBigDecimal(str);
diff --git a/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java b/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
index 735ff611d..c8398a051 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
@@ -244,7 +244,8 @@ public class ConstructorUtils {
// most of the time this works and it's much faster
try {
return MemberUtils.setAccessibleWorkaround(cls.getConstructor(parameterTypes));
- } catch (final NoSuchMethodException e) { // NOPMD - Swallow
+ } catch (final NoSuchMethodException ignored) {
+ // ignore
}
Constructor<T> result = null;
/*
diff --git a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java
index 663dfe18b..5668fcef2 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java
@@ -112,7 +112,7 @@ public class FieldUtils {
field.setAccessible(true);
}
return field;
- } catch (final NoSuchFieldException ex) { // NOPMD
+ } catch (final NoSuchFieldException ignored) {
// ignore
}
}
@@ -126,7 +126,7 @@ public class FieldUtils {
Validate.isTrue(match == null, "Reference to field %s is ambiguous relative to %s"
+ "; a matching field exists on two or more implemented interfaces.", fieldName, cls);
match = test;
- } catch (final NoSuchFieldException ex) { // NOPMD
+ } catch (final NoSuchFieldException ignored) {
// ignore
}
}
@@ -177,7 +177,7 @@ public class FieldUtils {
field.setAccessible(true);
}
return field;
- } catch (final NoSuchFieldException e) { // NOPMD
+ } catch (final NoSuchFieldException ignored) {
// ignore
}
return null;
diff --git a/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java b/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java
index 2592e2169..f79383913 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java
@@ -61,7 +61,7 @@ final class MemberUtils {
try {
obj.setAccessible(true);
return obj;
- } catch (final SecurityException e) { // NOPMD
+ } catch (final SecurityException ignored) {
// ignore in favor of subsequent IllegalAccessException
}
}
diff --git a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
index 3f2db41ad..a4b77a38f 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
@@ -625,7 +625,7 @@ public class MethodUtils {
try {
return anInterface.getDeclaredMethod(methodName,
parameterTypes);
- } catch (final NoSuchMethodException e) { // NOPMD
+ } catch (final NoSuchMethodException ignored) {
/*
* Swallow, if no method is found after the loop then this
* method returns null.
@@ -668,7 +668,8 @@ public class MethodUtils {
final String methodName, final Class<?>... parameterTypes) {
try {
return MemberUtils.setAccessibleWorkaround(cls.getMethod(methodName, parameterTypes));
- } catch (final NoSuchMethodException e) { // NOPMD - Swallow the exception
+ } catch (final NoSuchMethodException ignored) {
+ // Swallow the exception
}
// search through all methods
final Method[] methods = cls.getMethods();
diff --git a/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java b/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
index 0afa25253..d30ba9885 100644
--- a/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
+++ b/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
@@ -350,7 +350,7 @@ public class ExtendedMessageFormat extends MessageFormat {
if ((c == START_FMT || c == END_FE) && result.length() > 0) {
try {
return Integer.parseInt(result.toString());
- } catch (final NumberFormatException e) { // NOPMD
+ } catch (final NumberFormatException ignored) {
// we've already ensured only digits, so unless something
// outlandishly large was specified we should be okay.
}