mirror of https://github.com/apache/druid.git
add Class.getCanonicalName to forbidden-apis (#8086)
* add checkstyle to forbid unecessary use of Class.getCanonicalName * use forbiddin-api instead of checkstyle * add space
This commit is contained in:
parent
d3a6753df9
commit
15fbf5983d
|
@ -34,6 +34,7 @@ java.util.Random#<init>() @ Use ThreadLocalRandom.current() or the constructor w
|
|||
java.lang.Math#random() @ Use ThreadLocalRandom.current()
|
||||
java.util.regex.Pattern#matches(java.lang.String,java.lang.CharSequence) @ Use String.startsWith(), endsWith(), contains(), or compile and cache a Pattern explicitly
|
||||
org.apache.commons.io.FileUtils#getTempDirectory() @ Use org.junit.rules.TemporaryFolder for tests instead
|
||||
java.lang.Class#getCanonicalName() @ Class.getCanonicalName can return null for anonymous types, use Class.getName instead.
|
||||
|
||||
@defaultMessage Use Locale.ENGLISH
|
||||
com.ibm.icu.text.DateFormatSymbols#<init>()
|
||||
|
@ -45,4 +46,4 @@ org.apache.commons.codec.binary.Base64
|
|||
com.google.common.io.BaseEncoding.base64
|
||||
|
||||
@defaultMessage Use com.google.errorprone.annotations.concurrent.GuardedBy
|
||||
javax.annotations.concurrent.GuardedBy
|
||||
javax.annotations.concurrent.GuardedBy
|
||||
|
|
|
@ -54,7 +54,7 @@ public class GuiceInjectableValues extends InjectableValues
|
|||
}
|
||||
throw new IAE(
|
||||
"Unknown class type [%s] for valueId [%s]",
|
||||
valueId.getClass().getCanonicalName(),
|
||||
valueId.getClass().getName(),
|
||||
valueId.toString()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -432,8 +432,7 @@ public class Lifecycle
|
|||
for (Method method : o.getClass().getMethods()) {
|
||||
boolean doStart = false;
|
||||
for (Annotation annotation : method.getAnnotations()) {
|
||||
if ("org.apache.druid.java.util.common.lifecycle.LifecycleStart".equals(annotation.annotationType()
|
||||
.getCanonicalName())) {
|
||||
if (LifecycleStart.class.getName().equals(annotation.annotationType().getName())) {
|
||||
doStart = true;
|
||||
break;
|
||||
}
|
||||
|
@ -451,8 +450,7 @@ public class Lifecycle
|
|||
for (Method method : o.getClass().getMethods()) {
|
||||
boolean doStop = false;
|
||||
for (Annotation annotation : method.getAnnotations()) {
|
||||
if ("org.apache.druid.java.util.common.lifecycle.LifecycleStop".equals(annotation.annotationType()
|
||||
.getCanonicalName())) {
|
||||
if (LifecycleStop.class.getName().equals(annotation.annotationType().getName())) {
|
||||
doStop = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class DefaultPasswordProvider implements PasswordProvider
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getClass().getCanonicalName();
|
||||
return this.getClass().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -48,7 +48,7 @@ public class NamespaceLookupExtractorFactory implements LookupExtractorFactory
|
|||
private static final byte[] CLASS_CACHE_KEY;
|
||||
|
||||
static {
|
||||
final byte[] keyUtf8 = StringUtils.toUtf8(NamespaceLookupExtractorFactory.class.getCanonicalName());
|
||||
final byte[] keyUtf8 = StringUtils.toUtf8(NamespaceLookupExtractorFactory.class.getName());
|
||||
CLASS_CACHE_KEY = ByteBuffer.allocate(keyUtf8.length + 1).put(keyUtf8).put((byte) 0xFF).array();
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ public class OffHeapNamespaceExtractionCacheManager extends NamespaceExtractionC
|
|||
{
|
||||
super(lifecycle, serviceEmitter, config);
|
||||
try {
|
||||
tmpFile = File.createTempFile("druidMapDB", getClass().getCanonicalName());
|
||||
tmpFile = File.createTempFile("druidMapDB", getClass().getName());
|
||||
log.info("Using file [%s] for mapDB off heap namespace cache", tmpFile.getAbsolutePath());
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
|
|
@ -349,8 +349,8 @@ public class UriExtractionNamespaceTest
|
|||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
UriExtractionNamespace.ObjectMapperFlatDataParser.class.getCanonicalName(),
|
||||
namespace.getNamespaceParseSpec().getClass().getCanonicalName()
|
||||
UriExtractionNamespace.ObjectMapperFlatDataParser.class.getName(),
|
||||
namespace.getNamespaceParseSpec().getClass().getName()
|
||||
);
|
||||
Assert.assertEquals("file:/foo", namespace.getUriPrefix().toString());
|
||||
Assert.assertEquals("a.b.c", namespace.getFileRegex());
|
||||
|
@ -367,8 +367,8 @@ public class UriExtractionNamespaceTest
|
|||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
UriExtractionNamespace.ObjectMapperFlatDataParser.class.getCanonicalName(),
|
||||
namespace.getNamespaceParseSpec().getClass().getCanonicalName()
|
||||
UriExtractionNamespace.ObjectMapperFlatDataParser.class.getName(),
|
||||
namespace.getNamespaceParseSpec().getClass().getName()
|
||||
);
|
||||
Assert.assertEquals("file:/foo", namespace.getUri().toString());
|
||||
Assert.assertEquals(5L * 60_000L, namespace.getPollMs());
|
||||
|
|
|
@ -720,7 +720,7 @@ public class OverlordResource
|
|||
log.debug(
|
||||
"Task runner [%s] of type [%s] does not support listing workers",
|
||||
taskRunner,
|
||||
taskRunner.getClass().getCanonicalName()
|
||||
taskRunner.getClass().getName()
|
||||
);
|
||||
return Response.serverError()
|
||||
.entity(ImmutableMap.of("error", "Task Runner does not support worker listing"))
|
||||
|
|
|
@ -65,8 +65,8 @@ public abstract class SeekableStreamDataSourceMetadata<PartitionIdType, Sequence
|
|||
if (this.getClass() != other.getClass()) {
|
||||
throw new IAE(
|
||||
"Expected instance of %s, got %s",
|
||||
this.getClass().getCanonicalName(),
|
||||
other.getClass().getCanonicalName()
|
||||
this.getClass().getName(),
|
||||
other.getClass().getName()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -83,8 +83,8 @@ public abstract class SeekableStreamDataSourceMetadata<PartitionIdType, Sequence
|
|||
if (this.getClass() != other.getClass()) {
|
||||
throw new IAE(
|
||||
"Expected instance of %s, got %s",
|
||||
this.getClass().getCanonicalName(),
|
||||
other.getClass().getCanonicalName()
|
||||
this.getClass().getName(),
|
||||
other.getClass().getName()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -128,8 +128,8 @@ public class SeekableStreamEndSequenceNumbers<PartitionIdType, SequenceOffsetTyp
|
|||
if (this.getClass() != other.getClass()) {
|
||||
throw new IAE(
|
||||
"Expected instance of %s, got %s",
|
||||
this.getClass().getCanonicalName(),
|
||||
other.getClass().getCanonicalName()
|
||||
this.getClass().getName(),
|
||||
other.getClass().getName()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -155,8 +155,8 @@ public class SeekableStreamEndSequenceNumbers<PartitionIdType, SequenceOffsetTyp
|
|||
if (this.getClass() != other.getClass()) {
|
||||
throw new IAE(
|
||||
"Expected instance of %s, got %s",
|
||||
this.getClass().getCanonicalName(),
|
||||
other.getClass().getCanonicalName()
|
||||
this.getClass().getName(),
|
||||
other.getClass().getName()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -123,8 +123,8 @@ public class SeekableStreamStartSequenceNumbers<PartitionIdType, SequenceOffsetT
|
|||
if (this.getClass() != other.getClass()) {
|
||||
throw new IAE(
|
||||
"Expected instance of %s, got %s",
|
||||
this.getClass().getCanonicalName(),
|
||||
other.getClass().getCanonicalName()
|
||||
this.getClass().getName(),
|
||||
other.getClass().getName()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -169,8 +169,8 @@ public class SeekableStreamStartSequenceNumbers<PartitionIdType, SequenceOffsetT
|
|||
if (this.getClass() != other.getClass()) {
|
||||
throw new IAE(
|
||||
"Expected instance of %s, got %s",
|
||||
this.getClass().getCanonicalName(),
|
||||
other.getClass().getCanonicalName()
|
||||
this.getClass().getName(),
|
||||
other.getClass().getName()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ public class WorkerResource
|
|||
return Response.status(501)
|
||||
.entity(StringUtils.format(
|
||||
"Log streaming not supported by [%s]",
|
||||
taskRunner.getClass().getCanonicalName()
|
||||
taskRunner.getClass().getName()
|
||||
))
|
||||
.build();
|
||||
}
|
||||
|
|
|
@ -65,8 +65,8 @@ public class WrappedBitSetBitmap extends WrappedImmutableBitSetBitmap implements
|
|||
} else {
|
||||
throw new IAE(
|
||||
"Unknown class type: %s expected %s",
|
||||
mutableBitmap.getClass().getCanonicalName(),
|
||||
WrappedBitSetBitmap.class.getCanonicalName()
|
||||
mutableBitmap.getClass().getName(),
|
||||
WrappedBitSetBitmap.class.getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -79,8 +79,8 @@ public class WrappedBitSetBitmap extends WrappedImmutableBitSetBitmap implements
|
|||
} else {
|
||||
throw new IAE(
|
||||
"Unknown class type: %s expected %s",
|
||||
mutableBitmap.getClass().getCanonicalName(),
|
||||
WrappedBitSetBitmap.class.getCanonicalName()
|
||||
mutableBitmap.getClass().getName(),
|
||||
WrappedBitSetBitmap.class.getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -93,8 +93,8 @@ public class WrappedBitSetBitmap extends WrappedImmutableBitSetBitmap implements
|
|||
} else {
|
||||
throw new IAE(
|
||||
"Unknown class type: %s expected %s",
|
||||
mutableBitmap.getClass().getCanonicalName(),
|
||||
WrappedBitSetBitmap.class.getCanonicalName()
|
||||
mutableBitmap.getClass().getName(),
|
||||
WrappedBitSetBitmap.class.getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class StringFirstAggregator implements Aggregator
|
|||
} else {
|
||||
throw new ISE(
|
||||
"Try to aggregate unsuported class type [%s].Supported class types: String or SerializablePairLongString",
|
||||
value.getClass().getCanonicalName()
|
||||
value.getClass().getName()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public class StringFirstBufferAggregator implements BufferAggregator
|
|||
} else {
|
||||
throw new ISE(
|
||||
"Try to aggregate unsuported class type [%s].Supported class types: String or SerializablePairLongString",
|
||||
value.getClass().getCanonicalName()
|
||||
value.getClass().getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class StringLastAggregator implements Aggregator
|
|||
} else {
|
||||
throw new ISE(
|
||||
"Try to aggregate unsuported class type [%s].Supported class types: String or SerializablePairLongString",
|
||||
value.getClass().getCanonicalName()
|
||||
value.getClass().getName()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public class StringLastBufferAggregator implements BufferAggregator
|
|||
} else {
|
||||
throw new ISE(
|
||||
"Try to aggregate unsuported class type [%s].Supported class types: String or SerializablePairLongString",
|
||||
value.getClass().getCanonicalName()
|
||||
value.getClass().getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ public class DataSourceMetadataQueryRunnerFactory
|
|||
{
|
||||
Query<Result<DataSourceMetadataResultValue>> query = input.getQuery();
|
||||
if (!(query instanceof DataSourceMetadataQuery)) {
|
||||
throw new ISE("Got a [%s] which isn't a %s", query.getClass().getCanonicalName(), DataSourceMetadataQuery.class);
|
||||
throw new ISE("Got a [%s] which isn't a %s", query.getClass().getName(), DataSourceMetadataQuery.class);
|
||||
}
|
||||
|
||||
final DataSourceMetadataQuery legacyQuery = (DataSourceMetadataQuery) query;
|
||||
|
|
|
@ -96,7 +96,7 @@ public class RegisteredLookupExtractionFn implements ExtractionFn
|
|||
@Override
|
||||
public byte[] getCacheKey()
|
||||
{
|
||||
final byte[] keyPrefix = StringUtils.toUtf8(getClass().getCanonicalName());
|
||||
final byte[] keyPrefix = StringUtils.toUtf8(getClass().getName());
|
||||
final byte[] lookupName = StringUtils.toUtf8(getLookup());
|
||||
final byte[] delegateKey = ensureDelegate().getCacheKey();
|
||||
return ByteBuffer
|
||||
|
|
|
@ -61,7 +61,7 @@ public abstract class SearchStrategy
|
|||
} else if (bitmapFactory.getClass().equals(RoaringBitmapFactory.class)) {
|
||||
return RoaringBitmapDecisionHelper.instance();
|
||||
} else {
|
||||
throw new IAE("Unknown bitmap type[%s]", bitmapFactory.getClass().getCanonicalName());
|
||||
throw new IAE("Unknown bitmap type[%s]", bitmapFactory.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -807,7 +807,7 @@ public class QueryGranularityTest
|
|||
public void testDeadLock() throws Exception
|
||||
{
|
||||
final URL[] urls = ((URLClassLoader) Granularity.class.getClassLoader()).getURLs();
|
||||
final String className = Granularity.class.getCanonicalName();
|
||||
final String className = Granularity.class.getName();
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
final ClassLoader loader = new URLClassLoader(urls, null);
|
||||
Assert.assertNotNull(String.valueOf(i), Class.forName(className, true, loader));
|
||||
|
|
|
@ -279,7 +279,7 @@ public class CloserRuleTest
|
|||
runnable.run();
|
||||
}
|
||||
}, Description.createTestDescription(
|
||||
CloserRuleTest.class.getCanonicalName(), "baseRunner", UUID.randomUUID()
|
||||
CloserRuleTest.class.getName(), "baseRunner", UUID.randomUUID()
|
||||
)
|
||||
).evaluate();
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public class BitmapCreationBenchmark extends AbstractBenchmark
|
|||
{
|
||||
List<Class<? extends BitmapSerdeFactory>[]> classes = factoryClasses();
|
||||
for (int i = 0; i < classes.size(); ++i) {
|
||||
log.info("Entry [%d] is %s", i, classes.get(i)[0].getCanonicalName());
|
||||
log.info("Entry [%d] is %s", i, classes.get(i)[0].getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ public class Initialization
|
|||
|
||||
private void tryAdd(T serviceImpl, String extensionType)
|
||||
{
|
||||
final String serviceImplName = serviceImpl.getClass().getCanonicalName();
|
||||
final String serviceImplName = serviceImpl.getClass().getName();
|
||||
if (serviceImplName == null) {
|
||||
log.warn(
|
||||
"Implementation [%s] was ignored because it doesn't have a canonical name, "
|
||||
|
@ -474,7 +474,7 @@ public class Initialization
|
|||
|
||||
private boolean checkModuleClass(Class<?> moduleClass)
|
||||
{
|
||||
String moduleClassName = moduleClass.getCanonicalName();
|
||||
String moduleClassName = moduleClass.getName();
|
||||
if (moduleClassName != null && modulesConfig.getExcludeList().contains(moduleClassName)) {
|
||||
log.info("Not loading module [%s] because it is present in excludeList", moduleClassName);
|
||||
return false;
|
||||
|
|
|
@ -59,8 +59,8 @@ public class Log4jShutterDownerModule implements Module
|
|||
if (!(contextFactory instanceof Log4jContextFactory)) {
|
||||
log.warn(
|
||||
"Expected [%s] found [%s]. Unknown class for context factory. Not logging shutdown",
|
||||
Log4jContextFactory.class.getCanonicalName(),
|
||||
contextFactory.getClass().getCanonicalName()
|
||||
Log4jContextFactory.class.getName(),
|
||||
contextFactory.getClass().getName()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ public class Log4jShutterDownerModule implements Module
|
|||
if (!(registry instanceof Log4jShutdown)) {
|
||||
log.warn(
|
||||
"Shutdown callback registry expected class [%s] found [%s]. Skipping shutdown registry",
|
||||
Log4jShutdown.class.getCanonicalName(),
|
||||
registry.getClass().getCanonicalName()
|
||||
Log4jShutdown.class.getName(),
|
||||
registry.getClass().getName()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -161,8 +161,7 @@ public class StatusResource
|
|||
for (DruidModule module : druidModules) {
|
||||
String artifact = module.getClass().getPackage().getImplementationTitle();
|
||||
String version = module.getClass().getPackage().getImplementationVersion();
|
||||
|
||||
moduleVersions.add(new ModuleVersion(module.getClass().getCanonicalName(), artifact, version));
|
||||
moduleVersions.add(new ModuleVersion(module.getClass().getName(), artifact, version));
|
||||
}
|
||||
return moduleVersions;
|
||||
}
|
||||
|
|
|
@ -641,7 +641,7 @@ public class DruidCoordinator
|
|||
|
||||
log.info(
|
||||
"Done making indexing service helpers [%s]",
|
||||
helpers.stream().map(helper -> helper.getClass().getCanonicalName()).collect(Collectors.toList())
|
||||
helpers.stream().map(helper -> helper.getClass().getName()).collect(Collectors.toList())
|
||||
);
|
||||
return ImmutableList.copyOf(helpers);
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class InitializationTest
|
|||
@Override
|
||||
public String apply(@Nullable DruidModule input)
|
||||
{
|
||||
return input.getClass().getCanonicalName();
|
||||
return input.getClass().getName();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -107,8 +107,7 @@ public class InitializationTest
|
|||
|
||||
Assert.assertTrue(
|
||||
"modules contains TestDruidModule",
|
||||
Collections2.transform(modules, fnClassName)
|
||||
.contains("org.apache.druid.initialization.InitializationTest.TestDruidModule")
|
||||
Collections2.transform(modules, fnClassName).contains(TestDruidModule.class.getName())
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public class StatusResourceTest
|
|||
Assert.assertEquals("Status should have all modules loaded!", modules.size(), statusResourceModuleList.size());
|
||||
|
||||
for (DruidModule module : modules) {
|
||||
String moduleName = module.getClass().getCanonicalName();
|
||||
String moduleName = module.getClass().getName();
|
||||
|
||||
boolean contains = Boolean.FALSE;
|
||||
for (StatusResource.ModuleVersion version : statusResourceModuleList) {
|
||||
|
|
Loading…
Reference in New Issue