Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #12443: Fix null pointer exception on config value with trailin… #12444

Merged
merged 1 commit into from
Nov 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4574,6 +4574,10 @@
<param>com.puppycrawl.tools.checkstyle.filters.SuppressWithPlainTextCommentFilterTest</param>
<param>com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheckTest</param>
<param>com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheckTest</param>
<!-- kills mutation in AutomaticBean -->
<param>com.puppycrawl.tools.checkstyle.checks.naming.ParameterNameCheckTest</param>
<!-- kills mutation in AutomaticBean -->
<param>com.puppycrawl.tools.checkstyle.checks.coding.IllegalTypeCheckTest</param>
</targetTests>
<excludedTestClasses>
<param>*.Input*</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private static class RelaxedStringArrayConverter implements Converter {
@Override
public Object convert(Class type, Object value) {
final StringTokenizer tokenizer = new StringTokenizer(
value.toString(), COMMA_SEPARATOR);
value.toString().trim(), COMMA_SEPARATOR);
final List<String> result = new ArrayList<>();

while (tokenizer.hasMoreTokens()) {
Expand Down Expand Up @@ -390,7 +390,7 @@ private static class RelaxedAccessModifierArrayConverter implements Converter {
public Object convert(Class type, Object value) {
// Converts to a String and trims it for the tokenizer.
final StringTokenizer tokenizer = new StringTokenizer(
value.toString(), COMMA_SEPARATOR);
value.toString().trim(), COMMA_SEPARATOR);
final List<AccessModifierOption> result = new ArrayList<>();

while (tokenizer.hasMoreTokens()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,14 @@ public void testRecordComponentsPublicProtectedStatic() throws Exception {
expected);
}

@Test
public void testTrailingWhitespaceInConfig() throws Exception {
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verifyWithInlineConfigParser(
getPath("InputIllegalTypeWhitespaceInConfig.java"),
expected);
}

@Test
public void testTokensNotNull() {
final IllegalTypeCheck check = new IllegalTypeCheck();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,11 @@ public void testLambdaParameterNoViolationAtAll() throws Exception {
getPath("InputParameterNameLambda.java"), expected);
}

@Test
public void testWhitespaceInConfig() throws Exception {
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verifyWithInlineConfigParser(
getPath("InputParameterNameWhitespaceInConfig.java"), expected);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
IllegalType
validateAbstractClassNames = (default)false
illegalClassNames = java.lang.StringBuffer,\t
legalAbstractClassNames = (default)
ignoredMethodNames = (default)getEnvironment, getInitialContext
illegalAbstractClassNameFormat = (default)^(.*[.])?Abstract.*$
memberModifiers = (default)
tokens = (default)ANNOTATION_FIELD_DEF, CLASS_DEF, INTERFACE_DEF, METHOD_CALL, METHOD_DEF, \
METHOD_REF, PARAMETER_DEF, VARIABLE_DEF, PATTERN_VARIABLE_DEF, RECORD_DEF, \
RECORD_COMPONENT_DEF


*/
package com.puppycrawl.tools.checkstyle.checks.coding.illegaltype;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.util.List;

public class InputIllegalTypeWhitespaceInConfig {
public void example(List<@MyPattern String> strings) { // ok
}

@Target(ElementType.TYPE_USE)
public @interface MyPattern {}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
ParameterName
format = (default)^[a-z][a-zA-Z0-9]*$
ignoreOverridden = (default)false
accessModifiers = public\t,\t


*/

package com.puppycrawl.tools.checkstyle.checks.naming.parametername;

public class InputParameterNameWhitespaceInConfig {
int method(){return 1;} // ok
}