Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/linkcheck-suppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@
<td><i><a href="apidocs/com/puppycrawl/tools/checkstyle/utils/ParserUtil.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.</i></td></tr></table></td></tr>
<td><i><a href="apidocs/com/puppycrawl/tools/checkstyle/utils/ScopeUtil.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.</i></td></tr></table></td></tr>
<td><i><a href="apidocs/com/puppycrawl/tools/checkstyle/utils/TokenUtil.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.</i></td></tr></table></td></tr>
<td><i><a href="apidocs/com/puppycrawl/tools/checkstyle/utils/UnmodifiableCollectionUtil.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.</i></td></tr>
<td><i><a href="apidocs/com/puppycrawl/tools/checkstyle/utils/XpathUtil.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.</i></td></tr></table></td></tr>
<td><i><a href="apidocs/com/puppycrawl/tools/checkstyle/xpath/AbstractElementNode.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.xpath.AbstractNode,com.puppycrawl.tools.checkstyle.xpath.AbstractNode,int,int)">#%3Cinit%3E(com.puppycrawl.tools.checkstyle.xpath.AbstractNode,com.puppycrawl.tools.checkstyle.xpath.AbstractNode,int,int)</a>: doesn't exist.</i></td></tr>
<td><i><a href="apidocs/com/puppycrawl/tools/checkstyle/xpath/AbstractElementNode.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.xpath.AbstractNode,com.puppycrawl.tools.checkstyle.xpath.AbstractNode,int,int)">../AbstractElementNode.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.xpath.AbstractNode,com.puppycrawl.tools.checkstyle.xpath.AbstractNode,int,int)</a>: doesn't exist.</i></td></tr>
Expand Down Expand Up @@ -1289,6 +1290,7 @@
<td><i><a href="com/puppycrawl/tools/checkstyle/utils/ParserUtil.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/utils/ParserUtil.html#%3Cinit%3E()</a>: doesn't exist.</i></td></tr>
<td><i><a href="com/puppycrawl/tools/checkstyle/utils/ScopeUtil.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/utils/ScopeUtil.html#%3Cinit%3E()</a>: doesn't exist.</i></td></tr>
<td><i><a href="com/puppycrawl/tools/checkstyle/utils/TokenUtil.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/utils/TokenUtil.html#%3Cinit%3E()</a>: doesn't exist.</i></td></tr>
<td><i><a href="com/puppycrawl/tools/checkstyle/utils/UnmodifiableCollectionUtil.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/utils/UnmodifiableCollectionUtil.html#%3Cinit%3E()</a>: doesn't exist.</i></td></tr>
<td><i><a href="com/puppycrawl/tools/checkstyle/utils/XpathUtil.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/utils/XpathUtil.html#%3Cinit%3E()</a>: doesn't exist.</i></td></tr>
<td><i><a href="com/puppycrawl/tools/checkstyle/xpath/AbstractElementNode.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.xpath.AbstractNode,com.puppycrawl.tools.checkstyle.xpath.AbstractNode,int,int)">com/puppycrawl/tools/checkstyle/xpath/AbstractElementNode.html#%3Cinit%3E(com.puppycrawl.tools.checkstyle.xpath.AbstractNode,com.puppycrawl.tools.checkstyle.xpath.AbstractNode,int,int)</a>: doesn't exist.</i></td></tr>
<td><i><a href="com/puppycrawl/tools/checkstyle/xpath/AbstractNode.html#%3Cinit%3E(net.sf.saxon.om.TreeInfo)">com/puppycrawl/tools/checkstyle/xpath/AbstractNode.html#%3Cinit%3E(net.sf.saxon.om.TreeInfo)</a>: doesn't exist.</i></td></tr>
Expand Down
17 changes: 0 additions & 17 deletions config/pitest-suppressions/pitest-coding-1-suppressions.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<suppressedMutations>
<mutation unstable="false">
<sourceFile>EqualsAvoidNullCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck$FieldFrame</mutatedClass>
<mutatedMethod>getChildren</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.ArgumentPropagationMutator</mutator>
<description>replaced call to java/util/Collections::unmodifiableSet with argument</description>
<lineContent>return Collections.unmodifiableSet(children);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>EqualsAvoidNullCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck$FieldFrame</mutatedClass>
<mutatedMethod>getMethodCalls</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.ArgumentPropagationMutator</mutator>
<description>replaced call to java/util/Collections::unmodifiableSet with argument</description>
<lineContent>return Collections.unmodifiableSet(methodCalls);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VariableDeclarationUsageDistanceCheck.java</sourceFile>
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3219,6 +3219,9 @@
<param>com.puppycrawl.tools.checkstyle.checks.coding.SimplifyBooleanExpressionCheckTest</param>
<param>com.puppycrawl.tools.checkstyle.checks.coding.SimplifyBooleanReturnCheckTest</param>
</targetTests>
<avoidCallsTo>
<avoidCallsTo>com.puppycrawl.tools.checkstyle.utils.UnmodifiableCollectionUtil</avoidCallsTo>
</avoidCallsTo>
<excludedTestClasses>
<param>*.Input*</param>
</excludedTestClasses>
Expand Down Expand Up @@ -4748,6 +4751,9 @@
<!-- unkilled in generated code https://github.com/hcoles/pitest/issues/255 -->
<param>isFileExists</param>
</excludedMethods>
<excludedClasses>
<class>com.puppycrawl.tools.checkstyle.utils.UnmodifiableCollectionUtil</class>
</excludedClasses>
<targetTests>
<param>com.puppycrawl.tools.checkstyle.utils.*</param>
<!-- 12% mutation in CommonUtil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package com.puppycrawl.tools.checkstyle.checks.coding;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -30,6 +29,7 @@
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CheckUtil;
import com.puppycrawl.tools.checkstyle.utils.UnmodifiableCollectionUtil;

/**
* <p>
Expand Down Expand Up @@ -613,7 +613,7 @@ public FieldFrame getParent() {
* @return children of this frame.
*/
public Set<FieldFrame> getChildren() {
return Collections.unmodifiableSet(children);
return UnmodifiableCollectionUtil.unmodifiableSet(children);
}

/**
Expand Down Expand Up @@ -679,7 +679,7 @@ public DetailAST findField(String name) {
* @return method calls of this frame.
*/
public Set<DetailAST> getMethodCalls() {
return Collections.unmodifiableSet(methodCalls);
return UnmodifiableCollectionUtil.unmodifiableSet(methodCalls);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
// Copyright (C) 2001-2023 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
///////////////////////////////////////////////////////////////////////////////////////////////

package com.puppycrawl.tools.checkstyle.utils;

import java.util.Collections;
import java.util.Set;

/**
* <p>Note: it simply wraps the existing JDK methods to provide a workaround
* for Pitest survival on mutation for removal of immutable wrapping,
* see #13127 for more details.
* </p>
*
*/
public final class UnmodifiableCollectionUtil {

/**
* Private constructor for UnmodifiableCollectionUtil.
*
*/
private UnmodifiableCollectionUtil() {
}

/**
* Creates an unmodifiable set based on the provided collection.
*
* @param collection the collection to create an unmodifiable set from
* @param <T> the type of elements in the set
* @return an unmodifiable set containing the elements from the provided collection
*/
public static <T> Set<T> unmodifiableSet(Set<T> collection) {
return Collections.unmodifiableSet(collection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,16 @@ public void testTokensNotNull() {
.isNotNull();
}

@Test
public void testEqualAvoidNull() throws Exception {
final String[] expected = {
"12:17: " + getCheckMessage(MSG_EQUALS_AVOID_NULL),
"13:17: " + getCheckMessage(MSG_EQUALS_AVOID_NULL),
"14:17: " + getCheckMessage(MSG_EQUALS_AVOID_NULL),
"17:22: " + getCheckMessage(MSG_EQUALS_AVOID_NULL),
};

verifyWithInlineConfigParser(getPath("InputEqualsAvoidNull2.java"),
expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
EqualsAvoidNull


*/

package com.puppycrawl.tools.checkstyle.checks.coding.equalsavoidnull;

public class InputEqualsAvoidNull2 {
void foo() {
String s = "";
s.equals(s + s); // violation 'left .* of .* equals'
s.equals("a" + "b"); // violation 'left .* of .* equals'
s.equals(getInt() + s); // violation 'left .* of .* equals'
s.equals(getInt() + getInt());
s.endsWith("a");
if (!s.equals("Hi[EOL]"+System.getProperty(""))) // violation 'left.*of.*equals'
foo();
}

int getInt() {
return 0;
}

public void flagForEquals() {

Object o = new Object();
String s = "pizza";

o.equals("hot pizza")/*comment test*/;

o.equals(s = "cold pizza");

o.equals(((s = "cold pizza")));
}
}