javacheckstyle

Checkstyle lexicographical order error


I have following checkstyle configurations.

    <module name="CustomImportOrder">
        <property name="customImportOrderRules"
                  value="STATIC###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE###SAME_PACKAGE(3)"/>
        <property name="specialImportsRegExp" value="^org\."/>
        <property name="thirdPartyPackageRegExp" value="^com\."/>
        <property name="sortImportsInGroupAlphabetically" value="true"/>
        <property name="separateLineBetweenGroups" value="true"/>
    </module>

and then i have following list of imports

import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.Validate;

import com.google.common.collect.ImmutableMap;

import com.acompanyname.departmentname.commons.exceptions.DependencyFailureException;
import com.acompanyname.departmentname.commons.exceptions.DuplicateRecordException;
import com.acompanyname.departmentname.commons.exceptions.InvalidRequestException;
import com.acompanyname.departmentname.commons.exceptions.RecordNotFoundException;
import com.acompanyname.departmentname.financialservice.domain.Wallet;
import com.acompanyname.departmentname.financialservice.domain.WalletId;
import com.acompanyname.departmentname.financialservice.lambda.Converter;
import com.acompanyname.departmentname.financialservice.lambda.exceptions.DuplicateWalletException;
import com.amazonaws.AmazonClientException;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBSaveExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedScanList;
import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException;
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue;

for which i am constantly getting error that says Wrong lexicographical order for 'com.acompanyname.departmentname.commons.exceptions.DependencyFailureException' import.

I have tried multiple things and still unable to figure out how to fix this import error. I tried grouping them, re-ordering but still i am so confuse.


Solution

  • The error about the import order of com.acompanyname.departmentname.commons.exceptions.DependencyFailureException is misleading .

    The import that actually doesn't respect the lexicographical ordering with your configuration is :

    import com.google.common.collect.ImmutableMap;