diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 9f547408fc..006f5d5348 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -39,6 +39,7 @@ Fixed bug 3496028: pmd-4.2.6: MissingBreakInSwitch fails to report violation Fixed bug 3484404: Invalid NPath calculation in return statement. Thanks to Prabhjot Singh for the patch. Fixed bug 3560464: c/c++ \ as a continuation character not supported Fixed bug 3574133: False+ : SingularField +Fixed bug 3565001: Regression of Crash in PMDTask due to multithreading (Eclipse and Java 1.5) Improved JSP parser to be less strict with not valid XML documents (like HTML). Thanks to Victor Bucutea. Fixed bgastviewer not working. Thanks to Victor Bucutea. diff --git a/pmd/src/main/java/net/sourceforge/pmd/PMD.java b/pmd/src/main/java/net/sourceforge/pmd/PMD.java index 5fdefa2a67..c65545492b 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/PMD.java +++ b/pmd/src/main/java/net/sourceforge/pmd/PMD.java @@ -33,6 +33,7 @@ import net.sourceforge.pmd.processor.MultiThreadProcessor; import net.sourceforge.pmd.renderers.Renderer; import net.sourceforge.pmd.util.FileUtil; import net.sourceforge.pmd.util.IOUtil; +import net.sourceforge.pmd.util.SystemUtils; import net.sourceforge.pmd.util.datasource.DataSource; import net.sourceforge.pmd.util.log.ConsoleLogHandler; import net.sourceforge.pmd.util.log.ScopedLogHandlersManager; @@ -262,7 +263,7 @@ public class PMD { * disabled if threadCount is not positive, e.g. using the "-threads 0" * command line option. */ - if (configuration.getThreads() > 0) { + if (SystemUtils.MT_SUPPORTED && configuration.getThreads() > 0) { new MultiThreadProcessor(configuration).processFiles(ruleSetFactory, files, ctx, renderers); } else { new MonoThreadProcessor(configuration).processFiles(ruleSetFactory, files, ctx, renderers); diff --git a/pmd/src/main/java/net/sourceforge/pmd/util/SystemUtils.java b/pmd/src/main/java/net/sourceforge/pmd/util/SystemUtils.java new file mode 100644 index 0000000000..9ed9a015cd --- /dev/null +++ b/pmd/src/main/java/net/sourceforge/pmd/util/SystemUtils.java @@ -0,0 +1,41 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ +package net.sourceforge.pmd.util; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public final class SystemUtils { + + private SystemUtils() { + // this is a utility class and cannot be instantiated + } + + /** + * Do we have proper permissions to use multithreading? + */ + public static final boolean MT_SUPPORTED; + static { + boolean error = false; + try { + /* + * ant task ran from Eclipse with jdk 1.5.0 raises an AccessControlException + * when shutdown is called. Standalone pmd or ant from command line are fine. + * + * With jdk 1.6.0, ant task from Eclipse also works. + * + * Bugs related to this hack: + * 3565001 + * 1701832 + */ + ExecutorService executor = Executors.newFixedThreadPool(1); + executor.shutdown(); + } catch (RuntimeException e) { + error = true; + System.err.println("Disabling multithreading - consider to upgrade to java 1.6"); + System.err.println("See also: http://sourceforge.net/tracker/?func=detail&atid=479921&aid=1701832&group_id=56262"); + } + MT_SUPPORTED = !error; + } +}