Fix PMD violations of ExceptionAsFlowControl rule. #962

This commit is contained in:
Michal Kordas 2015-05-31 20:18:31 +02:00 committed by Roman Ivanov
parent 4b2962136f
commit fca6580f48
3 changed files with 65 additions and 77 deletions

View File

@ -193,8 +193,12 @@
<exclude name="AvoidCatchingGenericException"/>
<!-- till #961 -->
<exclude name="AvoidThrowingRawExceptionTypes"/>
<!-- till #962 -->
<exclude name="ExceptionAsFlowControl"/>
</rule>
<rule ref="rulesets/java/strictexception.xml/ExceptionAsFlowControl">
<properties>
<!-- till #1159 -->
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='PackageObjectFactory']"/>
</properties>
</rule>
<rule ref="rulesets/java/strictexception.xml/AvoidCatchingThrowable">
<properties>

View File

@ -34,7 +34,6 @@ import org.xml.sax.SAXParseException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@ -293,52 +292,42 @@ public final class ConfigurationLoader {
public static Configuration loadConfiguration(String config,
PropertyResolver overridePropsResolver, boolean omitIgnoredModules)
throws CheckstyleException {
// figure out if this is a File or a URL
URI uri;
try {
// figure out if this is a File or a URL
URI uri;
try {
final URL url = new URL(config);
uri = url.toURI();
final URL url = new URL(config);
uri = url.toURI();
}
catch (final MalformedURLException ex) {
uri = null;
}
catch (final URISyntaxException ex) {
// URL violating RFC 2396
uri = null;
}
if (uri == null) {
final File file = new File(config);
if (file.exists()) {
uri = file.toURI();
}
catch (final MalformedURLException ex) {
uri = null;
}
catch (final URISyntaxException ex) {
// URL violating RFC 2396
uri = null;
}
if (uri == null) {
final File file = new File(config);
if (file.exists()) {
uri = file.toURI();
else {
// check to see if the file is in the classpath
try {
final URL configUrl = ConfigurationLoader.class
.getResource(config);
if (configUrl == null) {
throw new CheckstyleException("unable to find " + config);
}
uri = configUrl.toURI();
}
else {
// check to see if the file is in the classpath
try {
final URL configUrl = ConfigurationLoader.class
.getResource(config);
if (configUrl == null) {
throw new FileNotFoundException(config);
}
uri = configUrl.toURI();
}
catch (final URISyntaxException e) {
throw new FileNotFoundException(config);
}
catch (final URISyntaxException e) {
throw new CheckstyleException("unable to find " + config);
}
}
final InputSource source = new InputSource(uri.toString());
return loadConfiguration(source, overridePropsResolver,
omitIgnoredModules);
}
catch (final FileNotFoundException e) {
throw new CheckstyleException("unable to find " + config, e);
}
catch (final CheckstyleException e) {
//wrap again to add file name info
throw new CheckstyleException("unable to read " + config + " - "
+ e.getMessage(), e);
}
final InputSource source = new InputSource(uri.toString());
return loadConfiguration(source, overridePropsResolver,
omitIgnoredModules);
}
/**

View File

@ -133,46 +133,41 @@ public final class SuppressionsLoader
*/
public static FilterSet loadSuppressions(String filename)
throws CheckstyleException {
// figure out if this is a File or a URL
URI uri;
try {
// figure out if this is a File or a URL
URI uri;
try {
final URL url = new URL(filename);
uri = url.toURI();
final URL url = new URL(filename);
uri = url.toURI();
}
catch (final MalformedURLException ex) {
uri = null;
}
catch (final URISyntaxException ex) {
// URL violating RFC 2396
uri = null;
}
if (uri == null) {
final File file = new File(filename);
if (file.exists()) {
uri = file.toURI();
}
catch (final MalformedURLException ex) {
uri = null;
}
catch (final URISyntaxException ex) {
// URL violating RFC 2396
uri = null;
}
if (uri == null) {
final File file = new File(filename);
if (file.exists()) {
uri = file.toURI();
else {
// check to see if the file is in the classpath
try {
final URL configUrl = SuppressionsLoader.class
.getResource(filename);
if (configUrl == null) {
throw new CheckstyleException("unable to find " + filename);
}
uri = configUrl.toURI();
}
else {
// check to see if the file is in the classpath
try {
final URL configUrl = SuppressionsLoader.class
.getResource(filename);
if (configUrl == null) {
throw new FileNotFoundException(filename);
}
uri = configUrl.toURI();
}
catch (final URISyntaxException e) {
throw new FileNotFoundException(filename);
}
catch (final URISyntaxException e) {
throw new CheckstyleException("unable to find " + filename);
}
}
final InputSource source = new InputSource(uri.toString());
return loadSuppressions(source, filename);
}
catch (final FileNotFoundException e) {
throw new CheckstyleException("unable to find " + filename, e);
}
final InputSource source = new InputSource(uri.toString());
return loadSuppressions(source, filename);
}
/**