diff --git a/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java b/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java index 6ed2b7d4f7..1bdb536163 100644 --- a/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java +++ b/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java @@ -21,7 +21,8 @@ public class CsTokenizer implements Tokenizer { BufferedReader reader = new BufferedReader(new CharArrayReader(sourceCode.getCodeBuffer().toString() .toCharArray())); try { - int ic = reader.read(), line = 1; + int ic = reader.read(); + int line = 1; char c; StringBuilder b; while (ic != -1) { @@ -50,16 +51,16 @@ public class CsTokenizer implements Tokenizer { case '>': ic = reader.read(); if (ic == '=') { - tokenEntries.add(new TokenEntry(String.valueOf(c) + "=", sourceCode.getFileName(), line)); + tokenEntries.add(new TokenEntry(c + "=", sourceCode.getFileName(), line)); ic = reader.read(); } else if (ic == c) { ic = reader.read(); if (ic == '=') { - tokenEntries.add(new TokenEntry(String.valueOf(c) + String.valueOf(c) + "=", sourceCode + tokenEntries.add(new TokenEntry("" + c + c + "=", sourceCode .getFileName(), line)); ic = reader.read(); } else { - tokenEntries.add(new TokenEntry(String.valueOf(c) + String.valueOf(c), sourceCode + tokenEntries.add(new TokenEntry("" + c + c, sourceCode .getFileName(), line)); } } else { @@ -75,7 +76,7 @@ public class CsTokenizer implements Tokenizer { case '-': ic = reader.read(); if (ic == '=' || ic == c) { - tokenEntries.add(new TokenEntry(String.valueOf(c) + String.valueOf((char) ic), sourceCode + tokenEntries.add(new TokenEntry("" + c + ((char) ic), sourceCode .getFileName(), line)); ic = reader.read(); } else { @@ -91,7 +92,7 @@ public class CsTokenizer implements Tokenizer { case '~': ic = reader.read(); if (ic == '=') { - tokenEntries.add(new TokenEntry(String.valueOf(c) + "=", sourceCode.getFileName(), line)); + tokenEntries.add(new TokenEntry(c + "=", sourceCode.getFileName(), line)); ic = reader.read(); } else { tokenEntries.add(new TokenEntry(String.valueOf(c), sourceCode.getFileName(), line)); @@ -104,17 +105,20 @@ public class CsTokenizer implements Tokenizer { b = new StringBuilder(); b.append(c); while ((ic = reader.read()) != c) { - if (ic == -1) + if (ic == -1) { break; + } b.append((char) ic); if (ic == '\\') { int next = reader.read(); - if (next != -1) + if (next != -1) { b.append((char) next); + } } } - if (ic != -1) + if (ic != -1) { b.append((char) ic); + } tokenEntries.add(new TokenEntry(b.toString(), sourceCode.getFileName(), line)); ic = reader.read(); break; @@ -132,8 +136,9 @@ public class CsTokenizer implements Tokenizer { b.append(c); if (state == 1) { - if (c == '*') + if (c == '*') { state = 2; + } } else { if (c == '/') { ic = reader.read(); @@ -152,8 +157,9 @@ public class CsTokenizer implements Tokenizer { b = new StringBuilder(); b.append("//"); while ((ic = reader.read()) != '\n') { - if (ic == -1) + if (ic == -1) { break; + } b.append((char) ic); } // ignore the // comment @@ -189,8 +195,9 @@ public class CsTokenizer implements Tokenizer { b.append(c); if (c == 'e' || c == 'E') { c = (char) (ic = reader.read()); - if ("1234567890-".indexOf(c) == -1) + if ("1234567890-".indexOf(c) == -1) { break; + } b.append(c); } c = (char) (ic = reader.read()); diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/DumpFacade.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/DumpFacade.java index 7b8a30537e..6755a79ab4 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/DumpFacade.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/DumpFacade.java @@ -17,7 +17,7 @@ public class DumpFacade { private boolean recurse; public void initializeWith(Writer writer, String prefix, boolean recurse, EcmascriptNode node) { - this.writer = (writer instanceof PrintWriter) ? (PrintWriter) writer : new PrintWriter(writer); + this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer); this.recurse = recurse; this.dump(node, prefix); try { diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptTreeBuilder.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptTreeBuilder.java index 5edbc1b50a..b8cff9175f 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptTreeBuilder.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptTreeBuilder.java @@ -132,14 +132,14 @@ public final class EcmascriptTreeBuilder implements NodeVisitor { } } - protected List parseProblems; - protected Map parseProblemToNode = new HashMap(); + private List parseProblems; + private Map parseProblemToNode = new HashMap(); // The nodes having children built. - protected Stack nodes = new Stack(); + private Stack nodes = new Stack(); // The Rhino nodes with children to build. - protected Stack parents = new Stack(); + private Stack parents = new Stack(); private final SourceCodePositioner sourceCodePositioner; diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/DumpFacade.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/DumpFacade.java index 556d3a8872..743412c488 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/DumpFacade.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/DumpFacade.java @@ -17,7 +17,7 @@ public class DumpFacade extends JspParserVisitorAdapter { private boolean recurse; public void initializeWith(Writer writer, String prefix, boolean recurse, JspNode node) { - this.writer = (writer instanceof PrintWriter) ? (PrintWriter) writer : new PrintWriter(writer); + this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer); this.recurse = recurse; this.visit(node, prefix); try { diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/OpenTagRegister.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/OpenTagRegister.java index 0a293dc579..a9f79f99ae 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/OpenTagRegister.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/OpenTagRegister.java @@ -23,9 +23,10 @@ public class OpenTagRegister { private List tagList = new ArrayList(); public void openTag(ASTElement elm) { - if (elm == null || StringUtil.isEmpty(elm.getName())) + if (elm == null || StringUtil.isEmpty(elm.getName())) { throw new IllegalStateException( "Tried to open a tag with empty name"); + } tagList.add(elm); } @@ -37,9 +38,10 @@ public class OpenTagRegister { * was ever opened ( or registered ) */ public boolean closeTag(String closingTagName) { - if (StringUtil.isEmpty(closingTagName)) + if (StringUtil.isEmpty(closingTagName)) { throw new IllegalStateException( "Tried to close a tag with empty name"); + } int lastRegisteredTagIdx = tagList.size() - 1; /* diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java b/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java index 8abbbea5a2..2cdcccfdc4 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java @@ -459,12 +459,8 @@ public abstract class AbstractRuleSetFactoryTest { .getPropertyDescriptors(); List> propertyDescriptors2 = rule2 .getPropertyDescriptors(); - try { - assertEquals(message + ", Rule property descriptor ", - propertyDescriptors1, propertyDescriptors2); - } catch (Error e) { - throw e; - } + assertEquals(message + ", Rule property descriptor ", + propertyDescriptors1, propertyDescriptors2); for (int j = 0; j < propertyDescriptors1.size(); j++) { assertEquals(message + ", Rule property value " + j, rule1 .getProperty(propertyDescriptors1.get(j)), rule2 diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/ant/AbstractAntTestHelper.java b/pmd-test/src/main/java/net/sourceforge/pmd/ant/AbstractAntTestHelper.java index a77a410077..2b9f31e30a 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/ant/AbstractAntTestHelper.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/ant/AbstractAntTestHelper.java @@ -45,8 +45,8 @@ public abstract class AbstractAntTestHelper extends BuildFileTest { private void validatePostConstruct() { if ( pathToTestScript == null || "".equals(pathToTestScript) || antTestScriptFilename == null || "".equals(antTestScriptFilename) || - mvnWorkaround == null || "".equals(mvnWorkaround) ) + mvnWorkaround == null || "".equals(mvnWorkaround) ) { throw new IllegalStateException("Unit tests for Ant script badly initialized"); - + } } } diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/cli/BaseCLITest.java b/pmd-test/src/main/java/net/sourceforge/pmd/cli/BaseCLITest.java index d32c06db1f..cbba244282 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/cli/BaseCLITest.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/cli/BaseCLITest.java @@ -84,8 +84,9 @@ public abstract class BaseCLITest { protected void checkStatusCode() { int statusCode = getStatusCode(); - if (statusCode > 0) + if (statusCode > 0) { fail("PMD failed with status code:" + statusCode); + } } protected int getStatusCode() { diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/testframework/RuleTst.java b/pmd-test/src/main/java/net/sourceforge/pmd/testframework/RuleTst.java index d5bb9acea6..8827c02ed3 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/testframework/RuleTst.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/testframework/RuleTst.java @@ -84,12 +84,12 @@ public abstract class RuleTst { if (test.getProperties() != null) { for (Map.Entry entry : test.getProperties().entrySet()) { String propertyName = (String)entry.getKey(); - String strValue = (String)entry.getValue(); PropertyDescriptor propertyDescriptor = rule.getPropertyDescriptor(propertyName); if (propertyDescriptor == null) { throw new IllegalArgumentException("No such property '" + propertyName + "' on Rule " + rule.getName()); } - Object value = propertyDescriptor.valueFrom(strValue); + + Object value = propertyDescriptor.valueFrom((String)entry.getValue()); rule.setProperty(propertyDescriptor, value); } } @@ -314,7 +314,6 @@ public abstract class RuleTst { String propertyName = ruleProperty.getAttributes().getNamedItem("name").getNodeValue(); properties.setProperty(propertyName, parseTextNode(ruleProperty)); } - int expectedProblems = Integer.parseInt(getNodeValue(testCode, "expected-problems", true)); NodeList expectedMessagesNodes = testCode.getElementsByTagName("expected-messages"); List messages = new ArrayList(); @@ -336,7 +335,6 @@ public abstract class RuleTst { } } - String description = getNodeValue(testCode, "description", true); String code = getNodeValue(testCode, "code", false); if (code == null) { //Should have a coderef @@ -359,6 +357,9 @@ public abstract class RuleTst { } } + String description = getNodeValue(testCode, "description", true); + int expectedProblems = Integer.parseInt(getNodeValue(testCode, "expected-problems", true)); + String languageVersionString = getNodeValue(testCode, "source-type", false); if (languageVersionString == null) { tests[i] = new TestDescriptor(code, description, expectedProblems, rule); diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/testframework/StreamUtil.java b/pmd-test/src/main/java/net/sourceforge/pmd/testframework/StreamUtil.java index aaa85d75c9..bd05960dcd 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/testframework/StreamUtil.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/testframework/StreamUtil.java @@ -9,13 +9,13 @@ import java.io.InputStream; import org.apache.commons.io.IOUtils; -public class StreamUtil { +public final class StreamUtil { + + private StreamUtil() { + // utility class + } public static String toString(InputStream in) { - if (in == null) { - throw new NullPointerException("no input stream given"); - } - StringBuilder sb = new StringBuilder(); int c; try { diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/testframework/TestDescriptor.java b/pmd-test/src/main/java/net/sourceforge/pmd/testframework/TestDescriptor.java index 4225b27f43..83a91b5152 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/testframework/TestDescriptor.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/testframework/TestDescriptor.java @@ -123,7 +123,6 @@ public class TestDescriptor { inRegressionMode = Boolean.parseBoolean(property); } } catch (IllegalArgumentException e) { - } catch (NullPointerException e) { } return inRegressionMode;