Fix PMD dogfood: AvoidCatchingThrowable

Refs #361
This commit is contained in:
Andreas Dangel
2018-02-13 13:34:20 +01:00
parent 4ace14899c
commit 7aaa9966c2
3 changed files with 36 additions and 30 deletions

View File

@ -1355,9 +1355,19 @@ public class ClassTypeResolver extends JavaParserVisitorAdapter {
private Class<?> processOnDemand(String qualifiedName) {
for (String entry : importedOnDemand) {
String fullClassName = entry + "." + qualifiedName;
try {
return pmdClassLoader.loadClass(entry + "." + qualifiedName);
} catch (Throwable e) {
return pmdClassLoader.loadClass(fullClassName);
} catch (ClassNotFoundException ignored) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Tried to load class " + fullClassName + " from on demand import, "
+ "which apparently doesn't exist.", ignored);
}
} catch (LinkageError ignored) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Tried to load class " + fullClassName + " from on demand import, "
+ "which apparently doesn't exist.", ignored);
}
}
}
return null;

View File

@ -138,9 +138,9 @@ public abstract class RuleTst {
report = processUsingStringReader(test, rule);
res = report.size();
} catch (Throwable t) {
t.printStackTrace();
throw new RuntimeException('"' + test.getDescription() + "\" failed", t);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException('"' + test.getDescription() + "\" failed", e);
}
if (test.getNumberOfProblemsExpected() != res) {
printReport(test, report);

View File

@ -113,37 +113,33 @@ public final class VelocityCharStream implements CharStream {
int[] newbufline = new int[bufsize + nextBufExpand];
int[] newbufcolumn = new int[bufsize + nextBufExpand];
try {
if (wrapAround) {
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
buffer = newbuffer;
if (wrapAround) {
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
buffer = newbuffer;
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
bufline = newbufline;
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
bufline = newbufline;
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
bufcolumn = newbufcolumn;
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
bufcolumn = newbufcolumn;
bufpos += bufsize - tokenBegin;
maxNextCharInd = bufpos;
} else {
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
buffer = newbuffer;
bufpos += bufsize - tokenBegin;
maxNextCharInd = bufpos;
} else {
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
buffer = newbuffer;
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
bufline = newbufline;
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
bufline = newbufline;
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
bufcolumn = newbufcolumn;
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
bufcolumn = newbufcolumn;
bufpos -= tokenBegin;
maxNextCharInd = bufpos;
}
} catch (Throwable t) {
throw new Error(t.getMessage());
bufpos -= tokenBegin;
maxNextCharInd = bufpos;
}
bufsize += nextBufExpand;