From e0f8fa05410cae075b68acd83a9dc787cedb1a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Wed, 7 Nov 2018 13:41:09 +0100 Subject: [PATCH 1/2] Prevent parsing to send too much noise to exception log The exceptions were reduced, but if we ended up on a parsable state, the last exception recorded was still output --- .../util/fxdesigner/EventLogController.java | 22 ++++++++++++++----- .../util/fxdesigner/XPathPanelController.java | 2 ++ .../pmd/util/fxdesigner/model/ASTManager.java | 6 ++++- .../pmd/util/fxdesigner/model/LogEntry.java | 11 +++++++--- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/EventLogController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/EventLogController.java index 60a0172639..4f786015c1 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/EventLogController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/EventLogController.java @@ -4,6 +4,10 @@ package net.sourceforge.pmd.util.fxdesigner; +import static net.sourceforge.pmd.util.fxdesigner.model.LogEntry.Category.*; +import static net.sourceforge.pmd.util.fxdesigner.model.LogEntry.Category.PARSE_EXCEPTION; +import static net.sourceforge.pmd.util.fxdesigner.model.LogEntry.Category.PARSE_OK; + import java.net.URL; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -89,16 +93,22 @@ public class EventLogController implements Initializable { }); EventStream onlyParseException = designerRoot.getLogger().getLog() - .filter(x -> x.getCategory() == Category.PARSE_EXCEPTION) - .successionEnds(PARSE_EXCEPTION_DELAY); + .filter(x -> x.getCategory() == PARSE_EXCEPTION || x.getCategory() == PARSE_OK) + .successionEnds(PARSE_EXCEPTION_DELAY) + // don't output anything when the last state recorded was OK + .filter(x -> x.getCategory() == PARSE_EXCEPTION); EventStream onlyXPathException = designerRoot.getLogger().getLog() - .filter(x -> x.getCategory() == Category.XPATH_EVALUATION_EXCEPTION) - .successionEnds(PARSE_EXCEPTION_DELAY); + .filter(x -> x.getCategory() == XPATH_EVALUATION_EXCEPTION || x.getCategory() == XPATH_OK) + .successionEnds(PARSE_EXCEPTION_DELAY) + .filter(x -> x.getCategory() == XPATH_EVALUATION_EXCEPTION); + EventStream otherExceptions = designerRoot.getLogger().getLog() - .filter(x -> x.getCategory() != Category.PARSE_EXCEPTION) - .filter(y -> y.getCategory() != Category.XPATH_EVALUATION_EXCEPTION); + .filter(x -> x.getCategory() != PARSE_EXCEPTION) + .filter(y -> y.getCategory() != XPATH_EVALUATION_EXCEPTION) + .filter(y -> y.getCategory() != PARSE_OK) + .filter(y -> y.getCategory() != XPATH_OK); EventStreams.merge(onlyParseException, otherExceptions, onlyXPathException) .subscribe(t -> eventLogTableView.getItems().add(t)); diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java index cadf8dea07..b9f0a319c4 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java @@ -313,6 +313,8 @@ public class XPathPanelController implements Initializable, SettingsOwner { xpathResultListView.setItems(results.stream().map(parent::wrapNode).collect(Collectors.toCollection(LiveArrayList::new))); parent.highlightXPathResults(results); violationsTitledPane.setText("Matched nodes\t(" + results.size() + ")"); + // Notify that everything went OK so we can avoid logging very recent exceptions + designerRoot.getLogger().logEvent(new LogEntry(null, Category.XPATH_OK)); } catch (XPathEvaluationException e) { invalidateResults(true); designerRoot.getLogger().logEvent(new LogEntry(e, Category.XPATH_EVALUATION_EXCEPTION)); diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/ASTManager.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/ASTManager.java index 29718e156d..5c260dceca 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/ASTManager.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/ASTManager.java @@ -104,7 +104,7 @@ public class ASTManager { try { languageVersionHandler.getQualifiedNameResolutionFacade(classLoader).start(node); } catch (Exception e) { - designerRoot.getLogger().logEvent(new LogEntry(e, Category.QUALIFIED_NAME_RESOLUTION_EXCEPTION)); + designerRoot.getLogger().logEvent(new LogEntry(e, Category.QNAME_RESOLUTION_EXCEPTION)); } try { @@ -116,6 +116,10 @@ public class ASTManager { compilationUnit.setValue(node); lastValidSource = source; lastLanguageVersion = getLanguageVersion(); + + // Notify that the parse went OK so we can avoid logging very recent exceptions + designerRoot.getLogger().logEvent(new LogEntry(null, Category.PARSE_OK)); + return getCompilationUnit(); } diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/LogEntry.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/LogEntry.java index 7d129630bf..a70deda233 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/LogEntry.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/LogEntry.java @@ -44,7 +44,7 @@ public class LogEntry { public String getStackTrace() { - return ExceptionUtils.getStackTrace(throwable); + return throwable == null ? "" : ExceptionUtils.getStackTrace(throwable); } @@ -56,10 +56,15 @@ public class LogEntry { public enum Category { PARSE_EXCEPTION("Parse exception"), TYPERESOLUTION_EXCEPTION("Type resolution exception"), - QUALIFIED_NAME_RESOLUTION_EXCEPTION("Qualified name resolution exception"), + QNAME_RESOLUTION_EXCEPTION("Qualified name resolution exception"), SYMBOL_FACADE_EXCEPTION("Symbol façade exception"), XPATH_EVALUATION_EXCEPTION("XPath evaluation exception"), - OTHER("Other"); + OTHER("Other"), + + // These are "flag" categories that signal that previous exceptions + // thrown during code or XPath edition may be discarded as uninteresting + PARSE_OK("Parsing success"), + XPATH_OK("XPath evaluation success"); public final String name; From 22f1ad5f5efcee4e023d21c5852bcf88c8b52d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 14 Jan 2019 16:47:18 +0100 Subject: [PATCH 2/2] Shorten code --- .../pmd/util/fxdesigner/EventLogController.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/EventLogController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/EventLogController.java index 4f786015c1..7adeb4f15a 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/EventLogController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/EventLogController.java @@ -4,9 +4,10 @@ package net.sourceforge.pmd.util.fxdesigner; -import static net.sourceforge.pmd.util.fxdesigner.model.LogEntry.Category.*; import static net.sourceforge.pmd.util.fxdesigner.model.LogEntry.Category.PARSE_EXCEPTION; import static net.sourceforge.pmd.util.fxdesigner.model.LogEntry.Category.PARSE_OK; +import static net.sourceforge.pmd.util.fxdesigner.model.LogEntry.Category.XPATH_EVALUATION_EXCEPTION; +import static net.sourceforge.pmd.util.fxdesigner.model.LogEntry.Category.XPATH_OK; import java.net.URL; import java.text.DateFormat; @@ -14,6 +15,7 @@ import java.text.SimpleDateFormat; import java.time.Duration; import java.util.Collections; import java.util.Date; +import java.util.EnumSet; import java.util.List; import java.util.Objects; import java.util.ResourceBundle; @@ -96,19 +98,18 @@ public class EventLogController implements Initializable { .filter(x -> x.getCategory() == PARSE_EXCEPTION || x.getCategory() == PARSE_OK) .successionEnds(PARSE_EXCEPTION_DELAY) // don't output anything when the last state recorded was OK - .filter(x -> x.getCategory() == PARSE_EXCEPTION); + .filter(x -> x.getCategory() != PARSE_OK); EventStream onlyXPathException = designerRoot.getLogger().getLog() .filter(x -> x.getCategory() == XPATH_EVALUATION_EXCEPTION || x.getCategory() == XPATH_OK) .successionEnds(PARSE_EXCEPTION_DELAY) - .filter(x -> x.getCategory() == XPATH_EVALUATION_EXCEPTION); + // don't output anything when the last state recorded was OK + .filter(x -> x.getCategory() != XPATH_OK); + EnumSet otherExceptionSet = EnumSet.complementOf(EnumSet.of(PARSE_EXCEPTION, XPATH_EVALUATION_EXCEPTION, PARSE_OK, XPATH_OK)); EventStream otherExceptions = designerRoot.getLogger().getLog() - .filter(x -> x.getCategory() != PARSE_EXCEPTION) - .filter(y -> y.getCategory() != XPATH_EVALUATION_EXCEPTION) - .filter(y -> y.getCategory() != PARSE_OK) - .filter(y -> y.getCategory() != XPATH_OK); + .filter(x -> otherExceptionSet.contains(x.getCategory())); EventStreams.merge(onlyParseException, otherExceptions, onlyXPathException) .subscribe(t -> eventLogTableView.getItems().add(t));