Skip to content

Commit

Permalink
Issue checkstyle#4456: Disallowing user to use incomplete fully quali…
Browse files Browse the repository at this point in the history
…fied Check names in config file
  • Loading branch information
djydewang committed Oct 12, 2017
1 parent 2a5690c commit e8e1e2e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
Expand Up @@ -170,14 +170,14 @@ public Object createModule(String name) throws CheckstyleException {
if (instance == null) {
instance = createObject(name);
}
final String nameCheck = name + CHECK_SUFFIX;
if (instance == null) {
instance = createObject(nameCheck);
}
if (instance == null) {
final String attemptedNames = joinPackageNamesWithClassName(name, packages)
+ STRING_SEPARATOR + nameCheck + STRING_SEPARATOR
+ joinPackageNamesWithClassName(nameCheck, packages);
String attemptedNames = null;
if (!name.contains(PACKAGE_SEPARATOR)) {
final String nameCheck = name + CHECK_SUFFIX;
attemptedNames = joinPackageNamesWithClassName(name, packages)
+ STRING_SEPARATOR + nameCheck + STRING_SEPARATOR
+ joinPackageNamesWithClassName(nameCheck, packages);
}
final LocalizedMessage exceptionMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE,
new String[] {name, attemptedNames}, null, getClass(), null);
Expand Down
Expand Up @@ -53,7 +53,6 @@
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.FileText;
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
import com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck;
import com.puppycrawl.tools.checkstyle.internal.utils.CheckUtil;

/**
Expand Down Expand Up @@ -122,12 +121,19 @@ public void testMakeObjectFromName()
}

@Test
public void testMakeCheckFromName()
throws CheckstyleException {
final ConstantNameCheck check =
(ConstantNameCheck) factory.createModule(
"com.puppycrawl.tools.checkstyle.checks.naming.ConstantName");
assertNotNull("Checker should not be null when creating module from name", check);
public void testMakeCheckFromName() {
final String name = "com.puppycrawl.tools.checkstyle.checks.naming.ConstantName";
try {
factory.createModule(name);
fail("Exception is expected");
}
catch (CheckstyleException ex) {
final LocalizedMessage exceptionMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE,
new String[] {name, null}, null, factory.getClass(), null);
assertEquals("Invalid exception message",
exceptionMessage.getMessage(), ex.getMessage());
}
}

@Test
Expand Down
4 changes: 1 addition & 3 deletions wercker.yml
Expand Up @@ -126,9 +126,7 @@ build:
echo CS_version: ${CS_POM_VERSION}
for i in 1 2 3 4 5; do git clone https://github.com/hibernate/hibernate-search.git && break || sleep 15; done
cd hibernate-search
git checkout 285c557fb51bbdf4bc81af8950c466f2ec336e9d
wget https://gist.githubusercontent.com/timurt/f8e6c08b681337dfee76fdf8cc4ebb37/raw/c95333027111d055de8c943d3bc0b757ad638605/hibernate.patch
git apply hibernate.patch
git checkout d3b7ea940c0933f5b5cb96163c9490a8a160e0d7
mvn -s settings-example.xml clean install -DskipTests=true -Dtest.elasticsearch.host.provided=true -Dpuppycrawl.checkstyle.version=${CS_POM_VERSION}
mvn -s settings-example.xml checkstyle:check -Dpuppycrawl.checkstyle.version=${CS_POM_VERSION}
cd ../
Expand Down

0 comments on commit e8e1e2e

Please sign in to comment.