From a81d142317f8dbc01f3866a5fd494d3f95999790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Tue, 10 Oct 2017 00:46:07 -0300 Subject: [PATCH] [core] Avoid a phony warning about not using cache - Avoid creating a NoopAnalysisCache by default to prevent a phony warning about not using the cache being printed. - This way, we only produce a new instance lazily if not configured, preserving the same behaviour bu without the warning. --- .../main/java/net/sourceforge/pmd/PMDConfiguration.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java index c59ed57c77..715aa41802 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java @@ -105,7 +105,7 @@ public class PMDConfiguration extends AbstractConfiguration { private boolean stressTest; private boolean benchmark; - private AnalysisCache analysisCache = new NoopAnalysisCache(); + private AnalysisCache analysisCache; /** * Get the suppress marker. This is the source level marker used to indicate @@ -567,6 +567,11 @@ public class PMDConfiguration extends AbstractConfiguration { * @return The currently used analysis cache. Never null. */ public AnalysisCache getAnalysisCache() { + // Make sure we are not null + if (analysisCache == null) { + setAnalysisCache(null); + } + return analysisCache; } @@ -592,7 +597,7 @@ public class PMDConfiguration extends AbstractConfiguration { */ public void setAnalysisCacheLocation(final String cacheLocation) { if (cacheLocation == null) { - setAnalysisCache(new NoopAnalysisCache()); + setAnalysisCache(null); } else { setAnalysisCache(new FileAnalysisCache(new File(cacheLocation))); }