From 6c7c4d6bc900f34fd629add3d21a9944eed447a4 Mon Sep 17 00:00:00 2001 From: Brian Remedios Date: Tue, 27 Dec 2011 15:54:36 +0000 Subject: [PATCH] Various bugfixes as identified by other analysis tools git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7607 51baf565-9d33-0410-a72c-fc3788e3496d --- .../eclipse/plugin/FileChangeReviewer.java | 1 + .../pmd/eclipse/plugin/PMDPlugin.java | 35 +++++++++---------- .../eclipse/runtime/builder/MarkerUtil.java | 2 +- .../impl/ProjectPropertiesImpl.java | 8 ++--- .../pmd/eclipse/ui/ShapeDescriptor.java | 1 + .../pmd/eclipse/ui/ShapePicker.java | 4 +-- .../ui/actions/ClearReviewsAction.java | 1 + .../preferences/GeneralPreferencesPage.java | 5 +-- .../PerRulePropertyPanelManager.java | 5 ++- .../ui/priority/PriorityDescriptor.java | 2 +- .../pmd/eclipse/ui/views/ViewMemento.java | 4 +-- 11 files changed, 35 insertions(+), 33 deletions(-) diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/plugin/FileChangeReviewer.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/plugin/FileChangeReviewer.java index e7c9a592fc..bf32d763df 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/plugin/FileChangeReviewer.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/plugin/FileChangeReviewer.java @@ -46,6 +46,7 @@ public class FileChangeReviewer implements IResourceChangeListener { public int hashCode() { return resourceDeltaType.hashCode() + 13 + file.hashCode() + flags; } public boolean equals(Object other) { + if (other == null) return false; if (other == this) return true; if (other.getClass() == getClass()) { ResourceChange chg = (ResourceChange)other; diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java index 0733288998..10fb5aeb17 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java @@ -518,15 +518,7 @@ public class PMDPlugin extends AbstractUIPlugin { } catch (CoreException e) { e.printStackTrace(); } - for (IResource irc : kids) { - if (irc instanceof IFile) { - allKids.add(irc); - continue; - } - if (irc instanceof IFolder) { - addFilesTo(irc, allKids); - } - } + addKids(allKids, kids); allKids.add(folder); return; @@ -540,19 +532,26 @@ public class PMDPlugin extends AbstractUIPlugin { } catch (CoreException e) { e.printStackTrace(); } - for (IResource irc : kids) { - if (irc instanceof IFile) { - allKids.add(irc); - continue; - } - if (irc instanceof IFolder) { - addFilesTo(irc, allKids); - } - } + addKids(allKids, kids); allKids.add(project); return; } } + + private void addKids(Collection allKids, IResource[] kids) { + + if (kids == null) return; + + for (IResource irc : kids) { + if (irc instanceof IFile) { + allKids.add(irc); + continue; + } + if (irc instanceof IFolder) { + addFilesTo(irc, allKids); + } + } + } public void removedMarkersIn(IResource resource) { diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/builder/MarkerUtil.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/builder/MarkerUtil.java index 89c003e057..ae081fe881 100755 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/builder/MarkerUtil.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/builder/MarkerUtil.java @@ -59,7 +59,7 @@ public class MarkerUtil { } catch (CoreException ex) { // what do to? } - if (ruleMarkers.length > 0) { + if (ruleMarkers != null && ruleMarkers.length > 0) { foundOne[0] = true; return false; } diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/properties/impl/ProjectPropertiesImpl.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/properties/impl/ProjectPropertiesImpl.java index 1bb935e7ab..63f4242e89 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/properties/impl/ProjectPropertiesImpl.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/properties/impl/ProjectPropertiesImpl.java @@ -165,11 +165,11 @@ public class ProjectPropertiesImpl implements IProjectProperties { * @see net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties#setRuleSetFile(String) */ public void setRuleSetFile(String ruleSetFile) throws PropertiesException { - log.debug("Set rule set file for project " + this.project.getName() + ": " + ruleSetFile); - this.needRebuild |= this.ruleSetFile == null || !ruleSetFile.equals(ruleSetFile); + log.debug("Set rule set file for project " + project.getName() + ": " + ruleSetFile); + needRebuild |= this.ruleSetFile == null || !this.ruleSetFile.equals(ruleSetFile); this.ruleSetFile = ruleSetFile; - if (this.ruleSetStoredInProject && !isRuleSetFileExist()) { - throw new PropertiesException("The project ruleset file cannot be found for project " + this.project.getName()); // TODO NLS + if (ruleSetStoredInProject && !isRuleSetFileExist()) { + throw new PropertiesException("The project ruleset file cannot be found for project " + project.getName()); // TODO NLS } } diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/ShapeDescriptor.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/ShapeDescriptor.java index 115d0f8e8c..018873d1d3 100755 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/ShapeDescriptor.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/ShapeDescriptor.java @@ -25,6 +25,7 @@ public class ShapeDescriptor implements Cloneable { public boolean equals(Object other) { + if (other == null) return false; if (this == other) return true; if (other.getClass() != getClass()) return false; diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/ShapePicker.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/ShapePicker.java index 4d86b4fa12..0887173156 100755 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/ShapePicker.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/ShapePicker.java @@ -155,7 +155,7 @@ public class ShapePicker extends Canvas implements ISelectionP switch (SWT.LEFT) { // TODO take from style bits case SWT.CENTER: xOffset = (width / 2) - (itemWidth / 2) - xBoundary + step; break; - case SWT.RIGHT: xOffset = width - width - xBoundary; break; + case SWT.RIGHT: xOffset = 0 - xBoundary; break; case SWT.LEFT: xOffset = xBoundary + step; } @@ -188,7 +188,7 @@ public class ShapePicker extends Canvas implements ISelectionP switch (SWT.LEFT) { // TODO take from style bits case SWT.CENTER: xOffset = (width / 2) - (itemWidth / 2) - xBoundary + step; break; - case SWT.RIGHT: xOffset = width - width - xBoundary; break; + case SWT.RIGHT: xOffset = 0 - xBoundary; break; case SWT.LEFT: xOffset = xBoundary + step; } diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/actions/ClearReviewsAction.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/actions/ClearReviewsAction.java index 3aeec3c257..cf3a0a8063 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/actions/ClearReviewsAction.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/actions/ClearReviewsAction.java @@ -256,6 +256,7 @@ public class ClearReviewsAction extends AbstractUIAction implements IResourceVis while (reader.ready()) { String origLine = reader.readLine(); String line = origLine.trim(); + if (line == null) break; int index = origLine.indexOf(PMDRuntimeConstants.PMD_STYLE_REVIEW_COMMENT); int quoteIndex = origLine.indexOf('"'); diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/preferences/GeneralPreferencesPage.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/preferences/GeneralPreferencesPage.java index fcea22f2c5..3f82ad938c 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/preferences/GeneralPreferencesPage.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/preferences/GeneralPreferencesPage.java @@ -728,7 +728,9 @@ System.out.println("updating icons"); } if (checkCodeOnSave != null) { - preferences.isCheckAfterSaveEnabled(checkCodeOnSave.getSelection()); + boolean doCheck = checkCodeOnSave.getSelection(); + preferences.isCheckAfterSaveEnabled(doCheck); + PMDPlugin.getDefault().fileChangeListenerEnabled(doCheck); } if (useCustomPriorityNames != null) { @@ -757,7 +759,6 @@ System.out.println("updating icons"); preferences.sync(); - PMDPlugin.getDefault().fileChangeListenerEnabled(checkCodeOnSave.getSelection()); PMDPlugin.getDefault().applyLogPreferences(preferences); return true; diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/preferences/panelmanagers/PerRulePropertyPanelManager.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/preferences/panelmanagers/PerRulePropertyPanelManager.java index 9cc7d9d510..32a9d7c1de 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/preferences/panelmanagers/PerRulePropertyPanelManager.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/preferences/panelmanagers/PerRulePropertyPanelManager.java @@ -187,9 +187,8 @@ public class PerRulePropertyPanelManager extends AbstractRulePanelManager implem return warnings; } - warnings.add("Unreferences variables: " + unreferencedVariables.toArray(new String[unreferencedVariables.size()])); - - + warnings.add("Unreferences variables: " + unreferencedVariables); + return warnings; } } diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/priority/PriorityDescriptor.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/priority/PriorityDescriptor.java index a7e1bac889..597732e598 100755 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/priority/PriorityDescriptor.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/priority/PriorityDescriptor.java @@ -99,7 +99,7 @@ public class PriorityDescriptor implements Cloneable { } public boolean equals(Object other) { - + if (other == null) return false; if (this == other) return true; if (other.getClass() != getClass()) return false; diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/views/ViewMemento.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/views/ViewMemento.java index 821da70746..e89f2739a8 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/views/ViewMemento.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/views/ViewMemento.java @@ -153,8 +153,8 @@ public class ViewMemento { contentReader = new BufferedReader(new FileReader(file)); while (contentReader.ready()) { - final String line = contentReader.readLine(); - if (line.length() != 0) { + String line = contentReader.readLine(); + if (line != null && line.length() != 0) { // the first Line of Text has to be the XML-Prefix isXmlFile = XML_PREFIX.equalsIgnoreCase(line); break;