Merge branch 'master' into 7.0.x

This commit is contained in:
Clément Fournier
2019-10-16 17:29:34 +02:00
43 changed files with 223 additions and 46 deletions

View File

@ -1310,9 +1310,8 @@ public class JuniorClass extends SeniorClass {
The dataflow analysis tracks local definitions, undefinitions and references to variables on different paths on the data flow.
From those informations there can be found various problems.
1. UR - Anomaly: There is a reference to a variable that was not defined before. This is a bug and leads to an error.
2. DU - Anomaly: A recently defined variable is undefined. These anomalies may appear in normal source text.
3. DD - Anomaly: A recently defined variable is redefined. This is ominous but don't have to be a bug.
1. DU - Anomaly: A recently defined variable is undefined. These anomalies may appear in normal source text.
2. DD - Anomaly: A recently defined variable is redefined. This is ominous but don't have to be a bug.
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.errorprone.DataflowAnomalyAnalysisRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/DataflowAnomalyAnalysisRule.java)

View File

@ -96,7 +96,7 @@ The tool comes with a rather extensive help text, simply running with `-help`!
default="5"
%}
{% include custom/cli_option_row.html options="-norulesetcompatibility"
description='Disables the ruleset compatibility filter. The filter is active by default. It tries to automatically replace rule references that point to moved or renamed rules with the newer location. Disabling it is not recommended.'
description='Disable automatic fixing of invalid rule references. Without the switch, PMD tries to automatically replace rule references that point to moved or renamed rules with the newer location if possible. Disabling it is not recommended.'
%}
{% include custom/cli_option_row.html options="-no-cache"
description="Explicitly disables incremental analysis. This switch turns off suggestions to use Incremental Analysis,

View File

@ -29,6 +29,10 @@ This is a {{ site.pmd.release_type }} release.
the builder needs to end with "Builder", e.g. `newBuilder()` or `initBuilder()` works. This change
fixes a couple of false positives.
* The Java rule {% rule "java/errorprone/DataflowAnomalyAnalysis" %} (`java-errorprone`) doesn't check for
UR anomalies (undefined and then referenced) anymore. These checks were all false-positives, since actual
UR occurrences would lead to compile errors.
### Fixed Issues
* core
@ -36,12 +40,18 @@ This is a {{ site.pmd.release_type }} release.
* [#2036](https://github.com/pmd/pmd/issues/2036): \[core] Wrong include/exclude patterns are silently ignored
* java
* [#2042](https://github.com/pmd/pmd/issues/2042): \[java] PMD crashes with ClassFormatError: Absent Code attribute...
* java-bestpractices
* [#2025](https://github.com/pmd/pmd/issues/2025): \[java] UnusedImports when @see / @link pattern includes a FQCN
* java-codestyle
* [#2017](https://github.com/pmd/pmd/issues/2017): \[java] UnnecessaryFullyQualifiedName triggered for inner class
* [#2017](https://github.com/pmd/pmd/issues/2017): \[java] UnnecessaryFullyQualifiedName triggered for inner class
* java-design
* [#1912](https://github.com/pmd/pmd/issues/1912): \[java] Metrics not computed correctly with annotations
* java-errorprone
* [#336](https://github.com/pmd/pmd/issues/336): \[java] InvalidSlf4jMessageFormat applies to log4j2
* [#1636](https://github.com/pmd/pmd/issues/1636): \[java] Stop checking UR anomalies for DataflowAnomalyAnalysis
* doc
* [#2058](https://github.com/pmd/pmd/issues/2058): \[doc] CLI reference for `-norulesetcompatibility` shows a boolean default value
### API Changes
@ -73,6 +83,15 @@ This is a {{ site.pmd.release_type }} release.
* {% jdoc apex::lang.apex.ast.CanSuppressWarnings %} and its implementations
* {% jdoc apex::lang.apex.rule.ApexRuleViolation#isSupressed(Node,Rule) %}
##### Internal APIs
* pmd-core
* All the package {% jdoc_package core::util %} and its subpackages,
except {% jdoc_package core::util.datasource %} and {% jdoc_package core::util.database %}.
* {% jdoc core::cpd.GridBagHelper %}
* {% jdoc core::renderers.ColumnDescriptor %}
### External Contributions
@ -80,6 +99,7 @@ This is a {{ site.pmd.release_type }} release.
* [#2012](https://github.com/pmd/pmd/pull/2012): \[java] Fixes 336, slf4j log4j2 support - [Mark Hall](https://github.com/markhall82)
* [#2032](https://github.com/pmd/pmd/pull/2032): \[core] Allow adding SourceCode directly into CPD - [Nathan Braun](https://github.com/nbraun-Google)
* [#2047](https://github.com/pmd/pmd/pull/2047): \[java] Fix computation of metrics with annotations - [Andi](https://github.com/andipabst)
* [#2065](https://github.com/pmd/pmd/pull/2065): \[java] Stop checking UR anomalies - [Carlos Macasaet](https://github.com/l0s)
{% endtocmaker %}

View File

@ -20,7 +20,6 @@ import org.apache.commons.lang3.StringUtils;
import net.sourceforge.pmd.lang.dfa.report.ReportTree;
import net.sourceforge.pmd.renderers.AbstractAccumulatingRenderer;
import net.sourceforge.pmd.util.DateTimeUtil;
import net.sourceforge.pmd.util.EmptyIterator;
import net.sourceforge.pmd.util.NumericConstants;
/**
@ -157,7 +156,7 @@ public class Report implements Iterable<RuleViolation> {
public String getMsg() {
return error.getClass().getSimpleName() + ": " + error.getMessage();
}
public String getDetail() {
try (StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter)) {
@ -441,7 +440,7 @@ public class Report implements Iterable<RuleViolation> {
* @return the iterator
*/
public Iterator<ProcessingError> errors() {
return errors == null ? EmptyIterator.<ProcessingError>instance() : errors.iterator();
return errors == null ? Collections.<ProcessingError>emptyIterator() : errors.iterator();
}
/**
@ -450,7 +449,7 @@ public class Report implements Iterable<RuleViolation> {
* @return the iterator
*/
public Iterator<ConfigurationError> configErrors() {
return configErrors == null ? EmptyIterator.<ConfigurationError>instance() : configErrors.iterator();
return configErrors == null ? Collections.<ConfigurationError>emptyIterator() : configErrors.iterator();
}
/**

View File

@ -13,6 +13,13 @@ import java.awt.Insets;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import net.sourceforge.pmd.annotation.InternalApi;
/**
* @deprecated Is internal API
*/
@Deprecated
@InternalApi
public class GridBagHelper {
GridBagLayout gridbag;

View File

@ -21,7 +21,6 @@ public final class IteratorUtil {
}
public static <T> Iterator<T> reverse(Iterator<T> it) {
List<T> tmp = toList(it);
Collections.reverse(tmp);

View File

@ -68,10 +68,10 @@ public class ImportWrapper {
}
if (other instanceof ImportWrapper) {
ImportWrapper i = (ImportWrapper) other;
if (name == null && i.getName() == null) {
return i.getFullName().equals(fullname);
if (name == null) {
return fullname.equals(i.getFullName());
}
return i.getName().equals(name);
return name.equals(i.getName());
}
return false;
}

View File

@ -4,12 +4,17 @@
package net.sourceforge.pmd.renderers;
import net.sourceforge.pmd.annotation.InternalApi;
/**
*
* @author Brian Remedios
*
* @param <T>
* @deprecated Is internal API
*/
@InternalApi
@Deprecated
public class ColumnDescriptor<T extends Object> {
public final String id;

View File

@ -17,7 +17,9 @@ import java.util.Map;
* UIs without the package prefixes.
*
* @author Brian Remedios
* @deprecated Is internal API
*/
@Deprecated
public final class ClassUtil {
public static final Class<?>[] EMPTY_CLASS_ARRAY = new Class[0];

View File

@ -19,17 +19,22 @@ import java.util.logging.Logger;
import org.apache.commons.lang3.StringUtils;
import net.sourceforge.pmd.annotation.InternalApi;
/**
* Create a ClassLoader which loads classes using a CLASSPATH like String. If
* the String looks like a URL to a file (e.g. starts with <code>file://</code>)
* the file will be read with each line representing an path on the classpath.
*
* @author Edwin Chan
* @deprecated Is internal API
*/
@InternalApi
@Deprecated
public class ClasspathClassLoader extends URLClassLoader {
private static final Logger LOG = Logger.getLogger(ClasspathClassLoader.class.getName());
static {
registerAsParallelCapable();
}
@ -102,7 +107,7 @@ public class ClasspathClassLoader extends URLClassLoader {
.append(StringUtils.join(getURLs(), ":"))
.append("] parent: ").append(getParent()).append(']').toString();
}
@Override
protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
synchronized (getClassLoadingLock(name)) {
@ -118,7 +123,7 @@ public class ClasspathClassLoader extends URLClassLoader {
c = super.loadClass(name, resolve);
}
}
if (resolve) {
resolveClass(c);
}

View File

@ -16,13 +16,18 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import net.sourceforge.pmd.annotation.InternalApi;
/**
* Generic collection and array-related utility functions for java.util types.
* See ClassUtil for comparable facilities for short name lookup.
*
* @author Brian Remedios
* @version $Revision$
* @deprecated Is internal API
*/
@Deprecated
@InternalApi
public final class CollectionUtil {
@SuppressWarnings("PMD.UnnecessaryFullyQualifiedName")

View File

@ -7,6 +7,8 @@ package net.sourceforge.pmd.util;
import java.util.Iterator;
import java.util.NoSuchElementException;
import net.sourceforge.pmd.annotation.InternalApi;
/**
* Creates a single compound Iterator from an array of Iterators.
*
@ -15,6 +17,8 @@ import java.util.NoSuchElementException;
*
* @see Iterator
*/
@InternalApi
@Deprecated
public class CompoundIterator<T> implements Iterator<T> {
private final Iterator<T>[] iterators;
private int index;

View File

@ -4,10 +4,14 @@
package net.sourceforge.pmd.util;
import net.sourceforge.pmd.annotation.InternalApi;
/**
*
* @author Brian Remedios
*/
@InternalApi
@Deprecated
public final class DateTimeUtil {
private DateTimeUtil() {

View File

@ -4,15 +4,21 @@
package net.sourceforge.pmd.util;
import java.util.Collections;
import java.util.Iterator;
import net.sourceforge.pmd.annotation.InternalApi;
/**
* A singleton iterator that never has anything.
*
* @author Brian Remedios
*
* @param <T>
* @deprecated Use {@link Collections#emptyIterator()}
*/
@InternalApi
@Deprecated
public final class EmptyIterator<T extends Object> implements Iterator<T> {
@SuppressWarnings("rawtypes")
@ -23,7 +29,7 @@ public final class EmptyIterator<T extends Object> implements Iterator<T> {
@SuppressWarnings("unchecked")
public static <T extends Object> Iterator<T> instance() {
return INSTANCE;
return Collections.emptyIterator();
}
@Override

View File

@ -12,9 +12,14 @@ import java.util.List;
import org.apache.commons.io.comparator.PathFileComparator;
import net.sourceforge.pmd.annotation.InternalApi;
/**
* A utility class for finding files within a directory.
* @deprecated Is internal API
*/
@Deprecated
@InternalApi
public class FileFinder {
private FilenameFilter filter;

View File

@ -9,6 +9,7 @@ import java.io.IOException;
import java.io.LineNumberReader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Iterator;
/**
@ -19,8 +20,9 @@ import java.util.Iterator;
* </p>
*
* @author Romain Pelisse &lt;belaran@gmail.com&gt;
*
* @deprecated Just use {@link Files#readAllLines(Path, Charset)} or {@code lines} on Java 8
*/
@Deprecated
public class FileIterable implements Iterable<String> {
private LineNumberReader lineReader = null;

View File

@ -5,8 +5,11 @@
package net.sourceforge.pmd.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
@ -20,6 +23,7 @@ import java.util.zip.ZipFile;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.util.datasource.DataSource;
import net.sourceforge.pmd.util.datasource.FileDataSource;
import net.sourceforge.pmd.util.datasource.ZipDataSource;
@ -30,7 +34,10 @@ import net.sourceforge.pmd.util.filter.OrFilter;
/**
* This is a utility class for working with Files.
* @deprecated Is internal API
*/
@Deprecated
@InternalApi
public final class FileUtil {
private FileUtil() {
@ -148,13 +155,19 @@ public final class FileUtil {
Pattern regexp = Pattern.compile(pattern);
Matcher matcher = regexp.matcher("");
FileIterable it = new FileIterable(file);
for (String line : it) {
matcher.reset(line); // reset the input
if (matcher.find()) {
return true;
try {
for (String line : Files.readAllLines(file.toPath(), StandardCharsets.UTF_8)) {
matcher.reset(line); // reset the input
if (matcher.find()) {
return true;
}
}
} catch (FileNotFoundException e) {
throw new IllegalArgumentException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
return false;
}
@ -162,7 +175,7 @@ public final class FileUtil {
* Reads the file, which contains the filelist. This is used for the
* command line arguments --filelist/-filelist for both PMD and CPD.
* The separator in the filelist is a command and/or newlines.
*
*
* @param filelist the file which contains the list of path names
* @return a comma-separated list of file paths
* @throws IOException if the file couldn't be read

View File

@ -17,10 +17,15 @@ import java.nio.file.Files;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import net.sourceforge.pmd.annotation.InternalApi;
/**
*
* @author Brian Remedios
* @deprecated Is internal API
*/
@InternalApi
@Deprecated
public final class IOUtil {
private IOUtil() {

View File

@ -4,13 +4,18 @@
package net.sourceforge.pmd.util;
/**
* @deprecated These constants were only useful before autoboxing was
* introduced, just use a literal or define your own constants
*/
@Deprecated
public final class NumericConstants {
public static final Integer ZERO = 0;
public static final Integer ONE = 1;
public static final Float FLOAT_ZERO = new Float(0.0f);
public static final Float FLOAT_ZERO = 0.0f;
private NumericConstants() { }
}

View File

@ -14,7 +14,13 @@ import java.nio.file.Files;
import java.util.Objects;
import net.sourceforge.pmd.RuleSetNotFoundException;
import net.sourceforge.pmd.annotation.InternalApi;
/**
* @deprecated Is internal API
*/
@Deprecated
@InternalApi
public class ResourceLoader {
public static final int TIMEOUT;
@ -79,7 +85,7 @@ public class ResourceLoader {
// We will throw our own exception, with a different message
}
}
throw new RuleSetNotFoundException("Can't find resource " + name
+ ". Make sure the resource is a valid file or URL or is on the CLASSPATH");
}
@ -102,7 +108,7 @@ public class ResourceLoader {
return connection.getInputStream();
}
}
public InputStream loadClassPathResourceAsStreamOrThrow(final String name) throws RuleSetNotFoundException {
InputStream is = null;
try {
@ -110,12 +116,12 @@ public class ResourceLoader {
} catch (final IOException ignored) {
// ignored
}
if (is == null) {
throw new RuleSetNotFoundException("Can't find resource " + name
+ ". Make sure the resource is on the CLASSPATH");
}
return is;
}
}

View File

@ -4,6 +4,10 @@
package net.sourceforge.pmd.util;
/**
* @deprecated Will be replaced with standard java.util.function.Predicate with 7.0.0
*/
@Deprecated
public interface SearchFunction<E> {
/**
* Applies the search function over a single element.

View File

@ -12,12 +12,17 @@ import java.util.Locale;
import org.apache.commons.lang3.StringUtils;
import net.sourceforge.pmd.annotation.InternalApi;
/**
* A number of String-specific utility methods for use by PMD or its IDE
* plugins.
*
* @author BrianRemedios
* @deprecated Is internal API
*/
@Deprecated
@InternalApi
public final class StringUtil {
private static final String[] EMPTY_STRINGS = new String[0];

View File

@ -8,6 +8,8 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import net.sourceforge.pmd.annotation.InternalApi;
/**
* A specialized map that stores types by both their full and short (without
* package prefixes) names. If an incoming type shares the same name (but
@ -16,7 +18,10 @@ import java.util.Map;
* said short name could be in error.
*
* @author Brian Remedios
* @deprecated Is internal API
*/
@Deprecated
@InternalApi
public class TypeMap {
private Map<String, Class<?>> typesByName;

View File

@ -14,7 +14,9 @@ import java.util.List;
*
* @param <T>
* The underlying type on which the filter applies.
* @deprecated See {@link Filter}
*/
@Deprecated
public abstract class AbstractCompoundFilter<T> implements Filter<T> {
protected List<Filter<T>> filters;

View File

@ -10,7 +10,9 @@ package net.sourceforge.pmd.util.filter;
*
* @param <T>
* The underlying type on which the filter applies.
* @deprecated See {@link Filter}
*/
@Deprecated
public abstract class AbstractDelegateFilter<T> implements Filter<T> {
protected Filter<T> filter;

View File

@ -9,7 +9,9 @@ package net.sourceforge.pmd.util.filter;
*
* @param <T>
* The underlying type on which the filter applies.
* @deprecated See {@link Filter}
*/
@Deprecated
public class AndFilter<T> extends AbstractCompoundFilter<T> {
public AndFilter() {

View File

@ -8,7 +8,9 @@ import java.io.File;
/**
* Directory filter.
* @deprecated See {@link Filter}
*/
@Deprecated
public final class DirectoryFilter implements Filter<File> {
public static final DirectoryFilter INSTANCE = new DirectoryFilter();

View File

@ -7,6 +7,10 @@ package net.sourceforge.pmd.util.filter;
import java.io.File;
import java.util.Locale;
/**
* @deprecated See {@link Filter}
*/
@Deprecated
public class FileExtensionFilter implements Filter<File> {
protected final String[] extensions;
protected final boolean ignoreCase;

View File

@ -9,7 +9,10 @@ package net.sourceforge.pmd.util.filter;
*
* @param <T>
* The underlying type on which the filter applies.
*
* @deprecated Will be replaced with standard java.util.function.Predicate with 7.0.0
*/
@Deprecated
public interface Filter<T> {
boolean filter(T obj);
}

View File

@ -10,10 +10,16 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.sourceforge.pmd.annotation.InternalApi;
/**
* Utility class for working with Filters. Contains builder style methods, apply
* methods, as well as mechanisms for adapting Filters and FilenameFilters.
*
* @deprecated Internal API, see {@link Filter}
*/
@Deprecated
@InternalApi
public final class Filters {
private Filters() { }

Some files were not shown because too many files have changed in this diff Show More