Issue #2616: Fix CatchParameterName check violations in Checkstyle code
This commit is contained in:
parent
d67d10e9f2
commit
f65b17cbc3
|
|
@ -165,7 +165,7 @@ public class BaseCheckTestSupport {
|
|||
try {
|
||||
pr.load(aClass.getResourceAsStream("messages.properties"));
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
return null;
|
||||
}
|
||||
final MessageFormat formatter = new MessageFormat(pr.getProperty(messageKey),
|
||||
|
|
|
|||
|
|
@ -231,14 +231,14 @@ public final class ConfigurationLoader {
|
|||
loader.parseInputSource(configSource);
|
||||
return loader.configuration;
|
||||
}
|
||||
catch (final SAXParseException e) {
|
||||
catch (final SAXParseException ex) {
|
||||
final String message = String.format(Locale.ROOT, "%s - %s:%s:%s",
|
||||
UNABLE_TO_PARSE_EXCEPTION_PREFIX,
|
||||
e.getMessage(), e.getLineNumber(), e.getColumnNumber());
|
||||
throw new CheckstyleException(message, e);
|
||||
ex.getMessage(), ex.getLineNumber(), ex.getColumnNumber());
|
||||
throw new CheckstyleException(message, ex);
|
||||
}
|
||||
catch (final ParserConfigurationException | IOException | SAXException e) {
|
||||
throw new CheckstyleException(UNABLE_TO_PARSE_EXCEPTION_PREFIX, e);
|
||||
catch (final ParserConfigurationException | IOException | SAXException ex) {
|
||||
throw new CheckstyleException(UNABLE_TO_PARSE_EXCEPTION_PREFIX, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -482,8 +482,8 @@ public final class ConfigurationLoader {
|
|||
final String severity = recentModule.getAttribute(SEVERITY);
|
||||
level = SeverityLevel.getInstance(severity);
|
||||
}
|
||||
catch (final CheckstyleException e) {
|
||||
LOG.debug("Severity not set, ignoring exception", e);
|
||||
catch (final CheckstyleException ex) {
|
||||
LOG.debug("Severity not set, ignoring exception", ex);
|
||||
}
|
||||
|
||||
// omit this module if these should be omitted and the module
|
||||
|
|
|
|||
|
|
@ -129,10 +129,10 @@ public final class Main {
|
|||
System.out.println(pex.getMessage());
|
||||
printUsage();
|
||||
}
|
||||
catch (CheckstyleException e) {
|
||||
catch (CheckstyleException ex) {
|
||||
exitStatus = EXIT_WITH_CHECKSTYLE_EXCEPTION_CODE;
|
||||
errorCounter = 1;
|
||||
e.printStackTrace();
|
||||
ex.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
// return exit code base on validation of Checker
|
||||
|
|
@ -300,9 +300,9 @@ public final class Main {
|
|||
fis = new FileInputStream(file);
|
||||
properties.load(fis);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
catch (final IOException ex) {
|
||||
throw new CheckstyleException(String.format(
|
||||
"Unable to load properties from file '%s'.", file.getAbsolutePath()), e);
|
||||
"Unable to load properties from file '%s'.", file.getAbsolutePath()), ex);
|
||||
}
|
||||
finally {
|
||||
Closeables.closeQuietly(fis);
|
||||
|
|
|
|||
|
|
@ -149,8 +149,8 @@ public final class PackageNamesLoader
|
|||
final InputSource source = new InputSource(stream);
|
||||
namesLoader.parseInputSource(source);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new CheckstyleException("unable to open " + packageFile, e);
|
||||
catch (IOException ex) {
|
||||
throw new CheckstyleException("unable to open " + packageFile, ex);
|
||||
}
|
||||
finally {
|
||||
Closeables.closeQuietly(stream);
|
||||
|
|
@ -160,11 +160,11 @@ public final class PackageNamesLoader
|
|||
result = namesLoader.packageNames;
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new CheckstyleException("unable to get package file resources", e);
|
||||
catch (IOException ex) {
|
||||
throw new CheckstyleException("unable to get package file resources", ex);
|
||||
}
|
||||
catch (ParserConfigurationException | SAXException e) {
|
||||
throw new CheckstyleException("unable to open one of package files", e);
|
||||
catch (ParserConfigurationException | SAXException ex) {
|
||||
throw new CheckstyleException("unable to open one of package files", ex);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -157,12 +157,12 @@ class PackageObjectFactory implements ModuleFactory {
|
|||
try {
|
||||
return doMakeObject(name + "Check");
|
||||
}
|
||||
catch (final CheckstyleException ex2) {
|
||||
catch (final CheckstyleException ex) {
|
||||
final LocalizedMessage exceptionMessage = new LocalizedMessage(0,
|
||||
Definitions.CHECKSTYLE_BUNDLE, UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE,
|
||||
new String[] {name, joinPackageNamesWithClassName(name)},
|
||||
null, getClass(), null);
|
||||
throw new CheckstyleException(exceptionMessage.getMessage(), ex2);
|
||||
throw new CheckstyleException(exceptionMessage.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -482,8 +482,8 @@ public final class TreeWalker
|
|||
try {
|
||||
cache.persist();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException("Unable to persist cache file", e);
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Unable to persist cache file", ex);
|
||||
}
|
||||
}
|
||||
super.destroy();
|
||||
|
|
|
|||
|
|
@ -364,8 +364,8 @@ public class CheckstyleAntTask extends Task {
|
|||
log("To process the files took " + (processingEndTime - processingStartTime)
|
||||
+ TIME_SUFFIX, Project.MSG_VERBOSE);
|
||||
}
|
||||
catch (CheckstyleException e) {
|
||||
throw new BuildException("Unable to process files: " + files, e);
|
||||
catch (CheckstyleException ex) {
|
||||
throw new BuildException("Unable to process files: " + files, ex);
|
||||
}
|
||||
final int numWarnings = warningCounter.getCount();
|
||||
final boolean okStatus = numErrs <= maxErrors && numWarnings <= maxWarnings;
|
||||
|
|
@ -412,9 +412,9 @@ public class CheckstyleAntTask extends Task {
|
|||
checker.contextualize(context);
|
||||
checker.configure(config);
|
||||
}
|
||||
catch (final CheckstyleException e) {
|
||||
catch (final CheckstyleException ex) {
|
||||
throw new BuildException(String.format(Locale.ROOT, "Unable to create a Checker: "
|
||||
+ "configLocation {%s}, classpath {%s}.", configLocation, classpath), e);
|
||||
+ "configLocation {%s}, classpath {%s}.", configLocation, classpath), ex);
|
||||
}
|
||||
return checker;
|
||||
}
|
||||
|
|
@ -435,9 +435,9 @@ public class CheckstyleAntTask extends Task {
|
|||
inStream = new FileInputStream(properties);
|
||||
returnValue.load(inStream);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
catch (final IOException ex) {
|
||||
throw new BuildException("Error loading Properties file '"
|
||||
+ properties + "'", e, getLocation());
|
||||
+ properties + "'", ex, getLocation());
|
||||
}
|
||||
finally {
|
||||
Closeables.closeQuietly(inStream);
|
||||
|
|
@ -482,9 +482,9 @@ public class CheckstyleAntTask extends Task {
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
throw new BuildException(String.format(Locale.ROOT, "Unable to create listeners: "
|
||||
+ "formatters {%s}.", formatters), e);
|
||||
+ "formatters {%s}.", formatters), ex);
|
||||
}
|
||||
return listeners;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,19 +169,19 @@ public class AutomaticBean
|
|||
beanUtils.copyProperty(this, key, value);
|
||||
}
|
||||
catch (final InvocationTargetException | IllegalAccessException
|
||||
| NoSuchMethodException e) {
|
||||
| NoSuchMethodException ex) {
|
||||
// There is no way to catch IllegalAccessException | NoSuchMethodException
|
||||
// as we do PropertyUtils.getPropertyDescriptor before beanUtils.copyProperty
|
||||
// so we have to join these exceptions with InvocationTargetException
|
||||
// to satisfy UTs coverage
|
||||
final String message = String.format(Locale.ROOT,
|
||||
"Cannot set property '%s' to '%s' in module %s", key, value, moduleName);
|
||||
throw new CheckstyleException(message, e);
|
||||
throw new CheckstyleException(message, ex);
|
||||
}
|
||||
catch (final IllegalArgumentException | ConversionException e) {
|
||||
catch (final IllegalArgumentException | ConversionException ex) {
|
||||
final String message = String.format(Locale.ROOT, "illegal value '%s' for property "
|
||||
+ "'%s' of module %s", value, key, moduleName);
|
||||
throw new CheckstyleException(message, e);
|
||||
throw new CheckstyleException(message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,8 +111,8 @@ public abstract class AbstractFormatCheck
|
|||
format = regexpFormat;
|
||||
compileFlags |= compileFlagsParam;
|
||||
}
|
||||
catch (final PatternSyntaxException e) {
|
||||
throw new ConversionException("unable to parse " + regexpFormat, e);
|
||||
catch (final PatternSyntaxException ex) {
|
||||
throw new ConversionException("unable to parse " + regexpFormat, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -390,8 +390,8 @@ public class TranslationCheck
|
|||
keys.add(element.nextElement());
|
||||
}
|
||||
}
|
||||
catch (final IOException e) {
|
||||
logIoException(e, file);
|
||||
catch (final IOException ex) {
|
||||
logIoException(ex, file);
|
||||
}
|
||||
finally {
|
||||
Closeables.closeQuietly(inStream);
|
||||
|
|
|
|||
|
|
@ -76,9 +76,9 @@ public class UniquePropertiesCheck extends AbstractFileSetCheck {
|
|||
fileInputStream.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
log(0, IO_EXCEPTION_KEY, file.getPath(),
|
||||
e.getLocalizedMessage());
|
||||
ex.getLocalizedMessage());
|
||||
}
|
||||
|
||||
for (Entry<String> duplication : properties
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
|
|||
* {@code
|
||||
* try {
|
||||
* throw new RuntimeException();
|
||||
* } catch (RuntimeException e) {
|
||||
* } catch (RuntimeException ex) {
|
||||
* //This is expected
|
||||
* }
|
||||
* }
|
||||
|
|
@ -110,7 +110,7 @@ import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
|
|||
* {@code
|
||||
* try {
|
||||
* throw new RuntimeException();
|
||||
* } catch (RuntimeException e) {
|
||||
* } catch (RuntimeException ex) {
|
||||
* //This is expected
|
||||
* }
|
||||
* }
|
||||
|
|
|
|||
|
|
@ -147,11 +147,11 @@ final class ImportControlLoader extends AbstractLoader {
|
|||
try {
|
||||
inputStream = uri.toURL().openStream();
|
||||
}
|
||||
catch (final MalformedURLException e) {
|
||||
throw new CheckstyleException("syntax error in url " + uri, e);
|
||||
catch (final MalformedURLException ex) {
|
||||
throw new CheckstyleException("syntax error in url " + uri, ex);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
throw new CheckstyleException("unable to find " + uri, e);
|
||||
catch (final IOException ex) {
|
||||
throw new CheckstyleException("unable to find " + uri, ex);
|
||||
}
|
||||
final InputSource source = new InputSource(inputStream);
|
||||
return load(source, uri);
|
||||
|
|
@ -171,12 +171,12 @@ final class ImportControlLoader extends AbstractLoader {
|
|||
loader.parseInputSource(source);
|
||||
return loader.getRoot();
|
||||
}
|
||||
catch (final ParserConfigurationException | SAXException e) {
|
||||
catch (final ParserConfigurationException | SAXException ex) {
|
||||
throw new CheckstyleException("unable to parse " + uri
|
||||
+ " - " + e.getMessage(), e);
|
||||
+ " - " + ex.getMessage(), ex);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
throw new CheckstyleException("unable to read " + uri, e);
|
||||
catch (final IOException ex) {
|
||||
throw new CheckstyleException("unable to read " + uri, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ public abstract class AbstractJavadocCheck extends Check {
|
|||
final DetailNode tree = convertParseTreeToDetailNode(parseTree);
|
||||
result.setTree(tree);
|
||||
}
|
||||
catch (ParseCancellationException e) {
|
||||
catch (ParseCancellationException ex) {
|
||||
// If syntax error occurs then message is printed by error listener
|
||||
// and parser throws this runtime exception to stop parsing.
|
||||
// Just stop processing current Javadoc comment.
|
||||
|
|
@ -243,7 +243,7 @@ public abstract class AbstractJavadocCheck extends Check {
|
|||
if (parseErrorMessage == null) {
|
||||
parseErrorMessage = new ParseErrorMessage(javadocCommentAst.getLineNo(),
|
||||
UNRECOGNIZED_ANTLR_ERROR_MESSAGE_KEY,
|
||||
javadocCommentAst.getColumnNo(), e.getMessage());
|
||||
javadocCommentAst.getColumnNo(), ex.getMessage());
|
||||
}
|
||||
|
||||
result.setParseErrorMessage(parseErrorMessage);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
|
|||
* <pre>
|
||||
* try {
|
||||
* thirdPartyLibrary.method();
|
||||
* } catch (RuntimeException e) {
|
||||
* } catch (RuntimeException ex) {
|
||||
* // ALLOW ILLEGAL CATCH BECAUSE third party API wraps everything
|
||||
* // in RuntimeExceptions.
|
||||
* ...
|
||||
|
|
@ -340,10 +340,10 @@ public class SuppressWithNearbyCommentFilter
|
|||
}
|
||||
influence = Integer.parseInt(format);
|
||||
}
|
||||
catch (final NumberFormatException e) {
|
||||
catch (final NumberFormatException ex) {
|
||||
throw new ConversionException(
|
||||
"unable to parse influence from '" + text
|
||||
+ "' using " + filter.influenceFormat, e);
|
||||
+ "' using " + filter.influenceFormat, ex);
|
||||
}
|
||||
if (influence >= 0) {
|
||||
firstLine = line;
|
||||
|
|
@ -354,10 +354,10 @@ public class SuppressWithNearbyCommentFilter
|
|||
lastLine = line;
|
||||
}
|
||||
}
|
||||
catch (final PatternSyntaxException e) {
|
||||
catch (final PatternSyntaxException ex) {
|
||||
throw new ConversionException(
|
||||
"unable to parse expanded comment " + format,
|
||||
e);
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -363,10 +363,10 @@ public class SuppressionCommentFilter
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (final PatternSyntaxException e) {
|
||||
catch (final PatternSyntaxException ex) {
|
||||
throw new ConversionException(
|
||||
"unable to parse expanded comment " + format,
|
||||
e);
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -144,21 +144,21 @@ public final class SuppressionsLoader
|
|||
suppressionsLoader.parseInputSource(source);
|
||||
return suppressionsLoader.filterChain;
|
||||
}
|
||||
catch (final FileNotFoundException e) {
|
||||
throw new CheckstyleException(UNABLE_TO_FIND_ERROR_MESSAGE + sourceName, e);
|
||||
catch (final FileNotFoundException ex) {
|
||||
throw new CheckstyleException(UNABLE_TO_FIND_ERROR_MESSAGE + sourceName, ex);
|
||||
}
|
||||
catch (final ParserConfigurationException | SAXException e) {
|
||||
catch (final ParserConfigurationException | SAXException ex) {
|
||||
final String message = String.format(Locale.ROOT, "Unable to parse %s - %s",
|
||||
sourceName, e.getMessage());
|
||||
throw new CheckstyleException(message, e);
|
||||
sourceName, ex.getMessage());
|
||||
throw new CheckstyleException(message, ex);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
throw new CheckstyleException("Unable to read " + sourceName, e);
|
||||
catch (final IOException ex) {
|
||||
throw new CheckstyleException("Unable to read " + sourceName, ex);
|
||||
}
|
||||
catch (final NumberFormatException e) {
|
||||
catch (final NumberFormatException ex) {
|
||||
final String message = String.format(Locale.ROOT, "Number format exception %s - %s",
|
||||
sourceName, e.getMessage());
|
||||
throw new CheckstyleException(message, e);
|
||||
sourceName, ex.getMessage());
|
||||
throw new CheckstyleException(message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -202,9 +202,9 @@ public final class CommonUtils {
|
|||
try {
|
||||
return Pattern.compile(pattern, flags);
|
||||
}
|
||||
catch (final PatternSyntaxException e) {
|
||||
catch (final PatternSyntaxException ex) {
|
||||
throw new ConversionException(
|
||||
"Failed to initialise regular expression " + pattern, e);
|
||||
"Failed to initialise regular expression " + pattern, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -333,8 +333,8 @@ public final class CommonUtils {
|
|||
try {
|
||||
closeable.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException("Cannot close the stream", e);
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Cannot close the stream", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -370,8 +370,8 @@ public final class CommonUtils {
|
|||
}
|
||||
uri = configUrl.toURI();
|
||||
}
|
||||
catch (final URISyntaxException e) {
|
||||
throw new CheckstyleException(UNABLE_TO_FIND_EXCEPTION_PREFIX + filename, e);
|
||||
catch (final URISyntaxException ex) {
|
||||
throw new CheckstyleException(UNABLE_TO_FIND_EXCEPTION_PREFIX + filename, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ public class BaseCheckTestSupport {
|
|||
try {
|
||||
pr.load(getClass().getResourceAsStream("messages.properties"));
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
return null;
|
||||
}
|
||||
final MessageFormat formatter = new MessageFormat(pr.getProperty(messageKey),
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ public class CommitValidationTest {
|
|||
new RevCommitsPair(new OmitMergeCommitsIterator(first),
|
||||
new OmitMergeCommitsIterator(second));
|
||||
}
|
||||
catch (GitAPIException | IOException e) {
|
||||
catch (GitAPIException | IOException ex) {
|
||||
revCommitIteratorPair = new RevCommitsPair();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -381,9 +381,9 @@ public class ConfigurationLoaderTest {
|
|||
fail("Exception is expected");
|
||||
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
assertTrue(e.getCause() instanceof IllegalStateException);
|
||||
assertEquals("Unknown name:" + "hello" + ".", e.getCause().getMessage());
|
||||
catch (InvocationTargetException ex) {
|
||||
assertTrue(ex.getCause() instanceof IllegalStateException);
|
||||
assertEquals("Unknown name:" + "hello" + ".", ex.getCause().getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -453,14 +453,14 @@ public class MainTest {
|
|||
}
|
||||
fail("Exception was expected");
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
assertTrue(e.getCause() instanceof CheckstyleException);
|
||||
catch (InvocationTargetException ex) {
|
||||
assertTrue(ex.getCause() instanceof CheckstyleException);
|
||||
// We do separate validation for message as in Windows
|
||||
// disk drive letter appear in message,
|
||||
// so we skip that drive letter for compatibility issues
|
||||
assertTrue(e.getCause().getMessage()
|
||||
assertTrue(ex.getCause().getMessage()
|
||||
.startsWith("Unable to load properties from file '"));
|
||||
assertTrue(e.getCause().getMessage().endsWith(":invalid'."));
|
||||
assertTrue(ex.getCause().getMessage().endsWith(":invalid'."));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -473,9 +473,9 @@ public class MainTest {
|
|||
method.invoke(null, "myformat", null);
|
||||
fail();
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
assertTrue(e.getCause() instanceof IllegalStateException);
|
||||
assertTrue(e.getCause().getMessage().startsWith("Invalid output format. Found"));
|
||||
catch (InvocationTargetException ex) {
|
||||
assertTrue(ex.getCause() instanceof IllegalStateException);
|
||||
assertTrue(ex.getCause().getMessage().startsWith("Invalid output format. Found"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -489,9 +489,9 @@ public class MainTest {
|
|||
method.invoke(null, "myformat", outDir);
|
||||
fail();
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
assertTrue(e.getCause() instanceof IllegalStateException);
|
||||
assertTrue(e.getCause().getMessage().startsWith("Invalid output format. Found"));
|
||||
catch (InvocationTargetException ex) {
|
||||
assertTrue(ex.getCause() instanceof IllegalStateException);
|
||||
assertTrue(ex.getCause().getMessage().startsWith("Invalid output format. Found"));
|
||||
}
|
||||
finally {
|
||||
// method creates output folder
|
||||
|
|
|
|||
|
|
@ -109,9 +109,9 @@ public class PropertyCacheFileTest {
|
|||
method.invoke(cache, config);
|
||||
fail();
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
assertTrue(e.getCause().getCause() instanceof NoSuchAlgorithmException);
|
||||
assertEquals("Unable to calculate hashcode.", e.getCause().getMessage());
|
||||
catch (InvocationTargetException ex) {
|
||||
assertTrue(ex.getCause().getCause() instanceof NoSuchAlgorithmException);
|
||||
assertEquals("Unable to calculate hashcode.", ex.getCause().getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,8 +93,8 @@ public class TreeWalkerTest extends BaseCheckTestSupport {
|
|||
verify(checkConfig, getPath("InputMain.java"), expected);
|
||||
fail();
|
||||
}
|
||||
catch (CheckstyleException e) {
|
||||
final String errorMsg = e.getMessage();
|
||||
catch (CheckstyleException ex) {
|
||||
final String errorMsg = ex.getMessage();
|
||||
assertTrue(errorMsg.contains("cannot initialize module"
|
||||
+ " com.puppycrawl.tools.checkstyle.TreeWalker - Token \"IMPORT\""
|
||||
+ " was not found in Acceptable tokens list in check"
|
||||
|
|
|
|||
|
|
@ -222,8 +222,8 @@ public class XDocsPagesTest {
|
|||
|
||||
return builder.parse(new InputSource(new StringReader(code)));
|
||||
}
|
||||
catch (IOException | SAXException e) {
|
||||
Assert.fail(fileName + " has invalid xml (" + e.getMessage() + "): "
|
||||
catch (IOException | SAXException ex) {
|
||||
Assert.fail(fileName + " has invalid xml (" + ex.getMessage() + "): "
|
||||
+ unserializedSource);
|
||||
}
|
||||
|
||||
|
|
@ -261,8 +261,8 @@ public class XDocsPagesTest {
|
|||
checker.destroy();
|
||||
}
|
||||
}
|
||||
catch (CheckstyleException e) {
|
||||
Assert.fail(fileName + " has invalid Checkstyle xml (" + e.getMessage() + "): "
|
||||
catch (CheckstyleException ex) {
|
||||
Assert.fail(fileName + " has invalid Checkstyle xml (" + ex.getMessage() + "): "
|
||||
+ unserializedSource);
|
||||
}
|
||||
}
|
||||
|
|
@ -320,7 +320,7 @@ public class XDocsPagesTest {
|
|||
try {
|
||||
instance = moduleFactory.createModule(sectionName);
|
||||
}
|
||||
catch (CheckstyleException e) {
|
||||
catch (CheckstyleException ex) {
|
||||
Assert.fail(fileName + " couldn't find class: " + sectionName);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ public class FileTextTest {
|
|||
new FileText(new File("any name"), charsetName);
|
||||
fail();
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
assertEquals("Unsupported charset: " + charsetName, e.getMessage());
|
||||
catch (UnsupportedEncodingException ex) {
|
||||
assertEquals("Unsupported charset: " + charsetName, ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class ClassResolverTest {
|
|||
classResolver.resolve("who.will.win.the.world.cup", "");
|
||||
fail("Should not resolve class");
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
catch (ClassNotFoundException ex) {
|
||||
// expected
|
||||
}
|
||||
classResolver.resolve("java.lang.String", "");
|
||||
|
|
@ -63,7 +63,7 @@ public class ClassResolverTest {
|
|||
classResolver.resolve("ChoiceFormat", "");
|
||||
fail();
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
catch (ClassNotFoundException ex) {
|
||||
// expected
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ public class ClassResolverTest {
|
|||
javaUtilClassResolver.resolve("two.nil.england", "");
|
||||
fail();
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
catch (ClassNotFoundException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
|
@ -96,9 +96,9 @@ public class ClassResolverTest {
|
|||
classResolver.resolve("someClass", "");
|
||||
fail("Exception expected");
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
catch (ClassNotFoundException ex) {
|
||||
// expected
|
||||
assertEquals("someClass", e.getMessage());
|
||||
assertEquals("someClass", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -144,10 +144,10 @@ public class ClassResolverTest {
|
|||
classResolver.resolve("someClass", "");
|
||||
fail("Exception expected");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (IllegalStateException ex) {
|
||||
// expected
|
||||
assertTrue(e.getCause() instanceof ClassNotFoundException);
|
||||
assertTrue(e.getMessage().endsWith("expected exception"));
|
||||
assertTrue(ex.getCause() instanceof ClassNotFoundException);
|
||||
assertTrue(ex.getMessage().endsWith("expected exception"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ public class FinalLocalVariableCheckTest
|
|||
check.visitToken(lambdaAst);
|
||||
Assert.fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (IllegalStateException ex) {
|
||||
// it is OK
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ public class IllegalInstantiationCheckTest
|
|||
check.visitToken(lambdaAst);
|
||||
Assert.fail();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
catch (IllegalArgumentException ex) {
|
||||
// it is OK
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ public class IllegalTypeCheckTest extends BaseCheckTestSupport {
|
|||
check.visitToken(classDefAst);
|
||||
Assert.fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (IllegalStateException ex) {
|
||||
// it is OK
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public class ModifiedControlVariableCheckTest
|
|||
check.visitToken(classDefAst);
|
||||
Assert.fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (IllegalStateException ex) {
|
||||
// it is OK
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ public class ModifiedControlVariableCheckTest
|
|||
check.leaveToken(classDefAst);
|
||||
Assert.fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (IllegalStateException ex) {
|
||||
// it is OK
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class ParameterAssignmentCheckTest extends BaseCheckTestSupport {
|
|||
check.visitToken(classDefAst);
|
||||
Assert.fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (IllegalStateException ex) {
|
||||
// it is OK
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ public class ParameterAssignmentCheckTest extends BaseCheckTestSupport {
|
|||
check.leaveToken(classDefAst);
|
||||
Assert.fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (IllegalStateException ex) {
|
||||
// it is OK
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public class ReturnCountCheckTest extends BaseCheckTestSupport {
|
|||
check.visitToken(classDefAst);
|
||||
Assert.fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (IllegalStateException ex) {
|
||||
// it is OK
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +134,7 @@ public class ReturnCountCheckTest extends BaseCheckTestSupport {
|
|||
check.leaveToken(classDefAst);
|
||||
Assert.fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (IllegalStateException ex) {
|
||||
// it is OK
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ public class MutableExceptionCheckTest extends BaseCheckTestSupport {
|
|||
obj.visitToken(ast);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (IllegalStateException ex) {
|
||||
//expected
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,8 +92,8 @@ public class ThrowsCountCheckTest extends BaseCheckTestSupport {
|
|||
obj.visitToken(ast);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
assertEquals(ast.toString(), e.getMessage());
|
||||
catch (IllegalStateException ex) {
|
||||
assertEquals(ast.toString(), ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ public class ImportControlLoaderTest {
|
|||
privateMethod.invoke(null, attr, "you_cannot_find_me");
|
||||
}
|
||||
catch (IllegalAccessException | IllegalArgumentException
|
||||
| NoSuchMethodException | SecurityException e) {
|
||||
throw new IllegalStateException(e);
|
||||
| NoSuchMethodException | SecurityException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -98,8 +98,8 @@ public class ImportControlLoaderTest {
|
|||
new File(getPath("import-control_complete.xml")).toURI());
|
||||
}
|
||||
catch (IllegalAccessException | IllegalArgumentException
|
||||
| NoSuchMethodException | SecurityException e) {
|
||||
throw new IllegalStateException(e);
|
||||
| NoSuchMethodException | SecurityException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,8 +195,8 @@ public class CommentsIndentationCheckTest extends BaseCheckTestSupport {
|
|||
check.visitToken(methodDef);
|
||||
Assert.fail("IllegalArgumentException should have been thrown!");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
final String msg = e.getMessage();
|
||||
catch (IllegalArgumentException ex) {
|
||||
final String msg = ex.getMessage();
|
||||
Assert.assertEquals("Unexpected token type: methodStub", msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,8 +204,8 @@ public class NoWhitespaceAfterCheckTest
|
|||
check.visitToken(astArrayDeclarator);
|
||||
fail("no intended exception thrown");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
assertEquals("unexpected ast syntaximport[0x-1]", e.getMessage());
|
||||
catch (IllegalStateException ex) {
|
||||
assertEquals("unexpected ast syntaximport[0x-1]", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ public class SuppressionsLoaderTest extends BaseCheckTestSupport {
|
|||
final HttpURLConnection urlConnect = (HttpURLConnection) verifiableUrl.openConnection();
|
||||
urlConnect.getContent();
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -287,7 +287,7 @@ public class JavadocParseTreeTest {
|
|||
public void syntaxError(
|
||||
Recognizer<?, ?> recognizer, Object offendingSymbol,
|
||||
int line, int charPositionInLine,
|
||||
String msg, RecognitionException e) {
|
||||
String msg, RecognitionException ex) {
|
||||
Assert.fail("[" + line + ", " + charPositionInLine + "] " + msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ public class TokenUtilsTest {
|
|||
assertEquals("given id " + id, expected.getMessage());
|
||||
|
||||
}
|
||||
catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
catch (IllegalAccessException | NoSuchFieldException ex) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue