Find duplicate lines with checkstyle; enable some duplicate inspections in IntelliJ (#6558)

Not putting this to 0.13 milestone because the found bugs are not critical (one is a harmless DI config duplicate, and another is in a benchmark.

Change in `DumpSegment` is just an indentation change.
This commit is contained in:
Roman Leventov 2018-11-26 16:55:42 +01:00 committed by GitHub
parent 03df481c9c
commit 887c645675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 68 additions and 67 deletions

View File

@ -29,6 +29,11 @@
<inspection_tool class="Contract" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="CopyConstructorMissesField" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="CovariantEquals" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="DuplicateBooleanBranch" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="DuplicateCondition" enabled="true" level="ERROR" enabled_by_default="true">
<option name="ignoreSideEffectConditions" value="true" />
</inspection_tool>
<inspection_tool class="DuplicateThrows" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="EmptyInitializer" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="EmptyStatementBody" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_reportEmptyBlocks" value="true" />
@ -71,6 +76,7 @@
<inspection_tool class="InvalidComparatorMethodReference" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="IteratorHasNextCallsIteratorNext" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="IteratorNextDoesNotThrowNoSuchElementException" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="JsonDuplicatePropertyKeys" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="JsonStandardCompliance" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="LengthOneStringInIndexOf" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="ListIndexOfReplaceableByContains" enabled="true" level="ERROR" enabled_by_default="true" />
@ -80,6 +86,8 @@
</inspection_tool>
<inspection_tool class="MalformedRegex" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="MathRandomCastToInt" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="MavenDuplicateDependenciesInspection" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="MavenDuplicatePluginInspection" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="MavenModelInspection" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="MismatchedArrayReadWrite" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="MismatchedCollectionQueryUpdate" enabled="true" level="ERROR" enabled_by_default="true">

View File

@ -282,7 +282,9 @@ public class SearchBenchmark
private static SearchQueryBuilder basicD(final BenchmarkSchemaInfo basicSchema)
{
final QuerySegmentSpec intervalSpec = new MultipleIntervalSegmentSpec(Collections.singletonList(basicSchema.getDataInterval()));
final QuerySegmentSpec intervalSpec = new MultipleIntervalSegmentSpec(
Collections.singletonList(basicSchema.getDataInterval())
);
final List<String> dimUniformFilterVals = new ArrayList<>();
final int resultNum = (int) (100000 * 0.1);
@ -296,9 +298,6 @@ public class SearchBenchmark
dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, null));
dimFilters.add(new SelectorDimFilter(dimName, "3", null));
dimFilters.add(new BoundDimFilter(dimName, "100", "10000", true, true, true, null, null));
dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, null));
dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, null));
dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, null));
return Druids.newSearchQueryBuilder()
.dataSource("blah")

View File

@ -50,13 +50,16 @@
<suppress checks="Indentation" files="[\\/]target[\\/]generated-test-sources[\\/]" />
<suppress checks="Indentation" files="ProtoTestEventWrapper.java" />
<suppress checks="Regex" files="ProtoTestEventWrapper.java" />
<suppress checks="Regexp" id="argumentLineBreaking" files="ProtoTestEventWrapper.java" />
<suppress checks="OneStatementPerLine" files="[\\/]target[\\/]generated-test-sources[\\/]" />
<!-- extendedset is a fork of Alessandro Colantonio's CONCISE (COmpressed 'N' Composable Integer SEt) repository and licensed to ASF under a CLA is not true. -->
<!-- extendedset is a fork of Alessandro Colantonio's CONCISE (COmpressed 'N' Composable Integer SEt) repository
and licensed to ASF under a CLA is not true. -->
<suppress checks="Header" files="[\\/]extendedset[\\/]" />
<suppress checks="Regexp" id="duplicateLine" files="[\\/]src[\\/]test[\\/]" />
<!-- See https://github.com/checkstyle/checkstyle/issues/5510 and the ImportOrder definition in checkstyle.xml -->
<suppress checks="ImportOrder" message="^'java\..*'.*" />

View File

@ -221,6 +221,7 @@
</module>
<module name="Regexp">
<property name="id" value="argumentLineBreaking"/>
<property
name="format"
value='(?&lt;!ImmutableMap.of|Types.mapOf|orderedMap|makeSelectResults|makeListOfPairs)\(\s*\n +([^,\n\(\{"&lt;/]+|[^,\n\(\{" /]+&gt; [a-zA-Z0-9_]+)\, ++[^,\n/]+'
@ -277,5 +278,12 @@ If you encouter a map-like or a pair-accepting method that is reported by this&#
checkstyle rule, you should add it as an exception in the corresponding rule in&#10;
codestyle/checkstyle.xml.&#10;"/>
</module>
<module name="Regexp">
<property name="id" value="duplicateLine"/>
<property name="format" value="^(.*;)(\r?\n\1)+$"/>
<property name="illegalPattern" value="true"/>
<property name="message" value="Duplicate line"/>
</module>
</module>
</module>

View File

@ -20,7 +20,6 @@
package org.apache.druid.jackson;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
@ -39,7 +38,7 @@ public class CommaListJoinDeserializer extends StdScalarDeserializer<List<String
@Override
public List<String> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException
throws IOException
{
return Arrays.asList(jsonParser.getText().split(","));
}

View File

@ -19,7 +19,6 @@
package org.apache.druid.jackson;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer;
@ -40,8 +39,7 @@ public class CommaListJoinSerializer extends StdScalarSerializer<List<String>>
}
@Override
public void serialize(List<String> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonGenerationException
public void serialize(List<String> value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
jgen.writeString(joiner.join(value));
}

View File

@ -20,7 +20,6 @@
package org.apache.druid.indexer;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -109,8 +108,7 @@ public class TaskStatusPlusTest
}
@Override
public DateTime deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {

View File

@ -20,7 +20,6 @@
package org.apache.druid.query.aggregation.datasketches.tuple;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.yahoo.sketches.tuple.ArrayOfDoublesSketch;
@ -35,7 +34,7 @@ public class ArrayOfDoublesSketchJsonSerializer extends JsonSerializer<ArrayOfDo
final ArrayOfDoublesSketch sketch,
final JsonGenerator generator,
final SerializerProvider provider
) throws IOException, JsonProcessingException
) throws IOException
{
generator.writeBinary(sketch.toByteArray());
}

View File

@ -276,12 +276,7 @@ public class JdbcExtractionNamespaceTest
}
);
Closeable closeable = () -> {
if (!setupFuture.isDone() && !setupFuture.cancel(true) && !setupFuture.isDone()) {
throw new IOException("Unable to stop future");
}
};
try (final Closeable c = closeable) {
try (final Closeable ignore = () -> setupFuture.cancel(true)) {
handleRef = setupFuture.get(10, TimeUnit.SECONDS);
}
Assert.assertNotNull(handleRef);

View File

@ -33,6 +33,5 @@ public class NullHandlingModule implements Module
{
JsonConfigProvider.bind(binder, "druid.generic", NullValueHandlingConfig.class);
binder.requestStaticInjection(NullHandling.class);
binder.requestStaticInjection(NullHandling.class);
}
}

View File

@ -21,7 +21,6 @@ package org.apache.druid.jackson;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
@ -70,8 +69,7 @@ public class DruidDefaultSerializersModule extends SimpleModule
DateTimeZone dateTimeZone,
JsonGenerator jsonGenerator,
SerializerProvider serializerProvider
)
throws IOException, JsonProcessingException
) throws IOException
{
jsonGenerator.writeString(dateTimeZone.getID());
}
@ -83,7 +81,7 @@ public class DruidDefaultSerializersModule extends SimpleModule
{
@Override
public void serialize(Sequence value, final JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException
throws IOException
{
jgen.writeStartArray();
value.accumulate(
@ -113,7 +111,7 @@ public class DruidDefaultSerializersModule extends SimpleModule
{
@Override
public void serialize(Yielder yielder, final JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException
throws IOException
{
try {
jgen.writeStartArray();

View File

@ -20,7 +20,6 @@
package org.apache.druid.jackson;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
@ -71,7 +70,7 @@ class JodaStuff
@Override
public Interval deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException
throws IOException
{
return Intervals.of(jsonParser.getText());
}
@ -94,8 +93,7 @@ class JodaStuff
}
@Override
public DateTime deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {

View File

@ -343,50 +343,49 @@ public class DumpSegment extends GuiceRunnable
@Override
public Object apply(final OutputStream out)
{
try {
final JsonGenerator jg = objectMapper.getFactory().createGenerator(out);
jg.writeStartObject();
jg.writeObjectField("bitmapSerdeFactory", bitmapSerdeFactory);
jg.writeFieldName("bitmaps");
try (final JsonGenerator jg = objectMapper.getFactory().createGenerator(out)) {
jg.writeStartObject();
{
jg.writeObjectField("bitmapSerdeFactory", bitmapSerdeFactory);
jg.writeFieldName("bitmaps");
jg.writeStartObject();
{
for (final String columnName : columnNames) {
final ColumnHolder columnHolder = index.getColumnHolder(columnName);
final BitmapIndex bitmapIndex = columnHolder.getBitmapIndex();
for (final String columnName : columnNames) {
final ColumnHolder columnHolder = index.getColumnHolder(columnName);
final BitmapIndex bitmapIndex = columnHolder.getBitmapIndex();
if (bitmapIndex == null) {
jg.writeNullField(columnName);
} else {
jg.writeFieldName(columnName);
jg.writeStartObject();
for (int i = 0; i < bitmapIndex.getCardinality(); i++) {
String val = NullHandling.nullToEmptyIfNeeded(bitmapIndex.getValue(i));
if (val != null) {
final ImmutableBitmap bitmap = bitmapIndex.getBitmap(i);
if (decompressBitmaps) {
jg.writeStartArray();
final IntIterator iterator = bitmap.iterator();
while (iterator.hasNext()) {
final int rowNum = iterator.next();
jg.writeNumber(rowNum);
}
jg.writeEndArray();
} else {
byte[] bytes = bitmapSerdeFactory.getObjectStrategy().toBytes(bitmap);
if (bytes != null) {
jg.writeBinary(bytes);
if (bitmapIndex == null) {
jg.writeNullField(columnName);
} else {
jg.writeFieldName(columnName);
jg.writeStartObject();
for (int i = 0; i < bitmapIndex.getCardinality(); i++) {
String val = NullHandling.nullToEmptyIfNeeded(bitmapIndex.getValue(i));
if (val != null) {
final ImmutableBitmap bitmap = bitmapIndex.getBitmap(i);
if (decompressBitmaps) {
jg.writeStartArray();
final IntIterator iterator = bitmap.iterator();
while (iterator.hasNext()) {
final int rowNum = iterator.next();
jg.writeNumber(rowNum);
}
jg.writeEndArray();
} else {
byte[] bytes = bitmapSerdeFactory.getObjectStrategy().toBytes(bitmap);
if (bytes != null) {
jg.writeBinary(bytes);
}
}
}
}
jg.writeEndObject();
}
}
jg.writeEndObject();
}
jg.writeEndObject();
}
jg.writeEndObject();
jg.writeEndObject();
jg.close();
}
catch (IOException e) {
throw Throwables.propagate(e);