Skip to content

Commit

Permalink
pmd: reintroducing check whether multi threading is support (bugfix f…
Browse files Browse the repository at this point in the history
…or 3565001)

 * created SystemUtils to check for multi-threading permission
Revert "pmd: Remove hack related to multithreading in jdk5 with Eclipse - no longer relevant today"

This reverts commit 720bb3d.
  • Loading branch information
adangel committed Oct 6, 2012
1 parent 28b37d6 commit 60c2af7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions pmd/etc/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion pmd/src/main/java/net/sourceforge/pmd/PMD.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;
Expand Down Expand Up @@ -262,7 +263,7 @@ public static void processFiles(final PMDConfiguration configuration,
* 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);
Expand Down
41 changes: 41 additions & 0 deletions pmd/src/main/java/net/sourceforge/pmd/util/SystemUtils.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 60c2af7

Please sign in to comment.