Skip to content

Commit 891acb0

Browse files
committed
Fix for #89 - Creating a HTML report without violations results in a nullpointer exception
1 parent eb8d23e commit 891acb0

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

src/com/intellij/plugins/bodhi/pmd/PMDInvoker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void run() {
157157
PMDResultPanel resultPanel = projectComponent.getResultPanel();
158158

159159
PMDRootNode rootNode = resultPanel.getRootNode();
160-
PMDResultCollector.report = null;
160+
PMDResultCollector.clearReport();
161161
rootNode.setFileCount(files.size());
162162
rootNode.setRuleSetCount(ruleSetPathArray.length);
163163
rootNode.setRunning(true);

src/com/intellij/plugins/bodhi/pmd/PMDResultPanel.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
import javax.swing.event.ChangeListener;
3232
import javax.swing.event.TreeSelectionEvent;
3333
import javax.swing.event.TreeSelectionListener;
34-
import javax.swing.tree.*;
34+
import javax.swing.tree.DefaultMutableTreeNode;
35+
import javax.swing.tree.DefaultTreeModel;
36+
import javax.swing.tree.TreeModel;
37+
import javax.swing.tree.TreePath;
3538
import java.awt.*;
3639
import java.awt.event.ActionEvent;
3740
import java.awt.event.ActionListener;
@@ -310,7 +313,7 @@ public void removeSettingsChangedListener(ChangeListener listener) {
310313
}
311314

312315
public String getReportText() {
313-
Report r = PMDResultCollector.report;
316+
Report r = PMDResultCollector.getReport();
314317
HTMLRenderer renderer = new HTMLRenderer();
315318
StringWriter w = new StringWriter();
316319
try {

src/com/intellij/plugins/bodhi/pmd/core/PMDResultCollector.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
import java.util.*;
2222

2323
/**
24-
* Responsible for running PMD and collecting the results which can be represeted in
24+
* Responsible for running PMD and collecting the results which can be represented in
2525
* tree format.
2626
*
2727
* @author bodhi
2828
* @version 1.3
2929
*/
3030
public class PMDResultCollector {
3131

32-
private Map<String, PMDBranchNode> ruleNameToNodeMap;
33-
public static Report report;
32+
private final Map<String, PMDBranchNode> ruleNameToNodeMap;
33+
private static Report report = new Report();
3434

3535
/**
3636
* Creates an instance of PMDResultCollector.
@@ -39,6 +39,20 @@ public PMDResultCollector() {
3939
ruleNameToNodeMap = new LinkedHashMap<>();
4040
} // linked to keep insertion order
4141

42+
/**
43+
* Clears the pmd results Report by assigning a new one
44+
*/
45+
public static void clearReport() {
46+
report = new Report();
47+
}
48+
49+
/**
50+
* Returns the report with pmd results
51+
* @return the report with pmd results
52+
*/
53+
public static Report getReport() {
54+
return report;
55+
}
4256
/**
4357
* Runs the given ruleSet(s) on given set of files and returns the result.
4458
*
@@ -122,7 +136,7 @@ private String shortMessage(String message)
122136
}
123137

124138
/**
125-
* Verifies whether the rule set specified at the path is a valid PMD ruleset.
139+
* Verifies whether the rule set specified at the path is a valid PMD rule set.
126140
*
127141
* @param path path of the rule set
128142
* @return true if valid rule set, false otherwise.
@@ -171,7 +185,7 @@ private class PMDResultRenderer extends AbstractIncrementingRenderer {
171185

172186
private final List<PMDBranchNode> pmdRuleResultNodes;
173187
private final PMDBranchNode processingErrorsNode;
174-
private Set<String> filesWithError = new HashSet();
188+
private final Set<String> filesWithError = new HashSet<>();
175189

176190
public PMDResultRenderer(List<PMDBranchNode> pmdRuleSetResults, PMDBranchNode errorsNode) {
177191
super("pmdplugin", "PMD plugin renderer");
@@ -182,9 +196,6 @@ public PMDResultRenderer(List<PMDBranchNode> pmdRuleSetResults, PMDBranchNode er
182196
@Override
183197
public void renderFileViolations(Iterator<RuleViolation> violations) throws IOException {
184198
PMDTreeNodeFactory nodeFactory = PMDTreeNodeFactory.getInstance();
185-
if (PMDResultCollector.report == null) {
186-
PMDResultCollector.report = new Report();
187-
}
188199
while (violations.hasNext()) {
189200
RuleViolation iRuleViolation = violations.next();
190201
PMDResultCollector.report.addRuleViolation(iRuleViolation);

src/com/intellij/plugins/bodhi/pmd/handlers/PMDCheckinHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public class PMDCheckinHandler extends CheckinHandler {
4242
@NonNls
4343
private final CheckinProjectPanel checkinProjectPanel;
4444

45-
/* default */ PMDCheckinHandler(CheckinProjectPanel checkinProjectPanel) {
45+
/* default */
46+
PMDCheckinHandler(CheckinProjectPanel checkinProjectPanel) {
4647
this.checkinProjectPanel = checkinProjectPanel;
4748
}
4849

@@ -102,7 +103,7 @@ public ReturnResult beforeCheckin(@Nullable CommitExecutor executor,
102103
return ReturnResult.COMMIT;
103104
}
104105

105-
PMDResultCollector.report = null;
106+
PMDResultCollector.clearReport();
106107

107108
List<PMDBranchNode> ruleSetResultNodes = new ArrayList<>();
108109
for (String ruleSetPath : plugin.getCustomRuleSetPaths()) {

0 commit comments

Comments
 (0)