Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import javax.validation.Validation;
import javax.validation.Validator;

import java.util.Properties;
import java.util.UUID;

Expand Down
4 changes: 4 additions & 0 deletions codestyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
<property name="tokens" value="INTERFACE_DEF,ENUM_DEF,METHOD_DEF"/>
</module>

<module name="hu.rxd.checkstyle.FunctionArgsAlignmentRule">
<property name="exclude" value="of,mapOf,makeMap,orderedMap,makeSelectResults,makeListOfPairs,mapMatcher,makeRow,createExpectedRow,createExpected,assertEquals,checkArgument,permuteArguments,newArrayList,asList,newHashSet"/>
</module>

<!-- See http://checkstyle.sourceforge.net/checks.html for examples -->

<!--<module name="LineLength">-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector;

import javax.annotation.Nullable;

import java.nio.ByteBuffer;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import java.io.IOException;
import java.util.List;

Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,11 @@
<artifactId>checkstyle</artifactId>
<version>8.21</version>
</dependency>
<dependency>
<groupId>hu.rxd</groupId>
<artifactId>checkstyle-plugins</artifactId>
<version>0.0.4</version>
</dependency>
</dependencies>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@ public JavaType handleUnknownTypeId(DeserializationContext ctxt,
throws IOException
{
String serviceMsg = (serviceName == null) ? "" : StringUtils.format(" on '%s' service", serviceName);
String msg = StringUtils.format("Please make sure to load all the necessary extensions and jars " +
"with type '%s'%s. " +
String msg = StringUtils.format(
"Please make sure to load all the necessary extensions and jars with type '%s'%s. " +
"Could not resolve type id '%s' as a subtype of %s",
subTypeId, serviceMsg, subTypeId, ClassUtil.getTypeDescription(baseType));
subTypeId,
serviceMsg,
subTypeId,
ClassUtil.getTypeDescription(baseType));
String extraFailureMsg = (failureMsg == null) ? msg : msg + " " + failureMsg;
throw InvalidTypeIdException.from(ctxt.getParser(), extraFailureMsg, baseType, subTypeId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,16 @@ private static MethodHandle unmapJava7Or8(MethodHandles.Lookup lookup) throws Re
MethodHandle directBufferCleanerMethod = lookup.unreflect(m);
Class<?> cleanerClass = directBufferCleanerMethod.type().returnType();
MethodHandle cleanMethod = lookup.findVirtual(cleanerClass, "clean", MethodType.methodType(void.class));
MethodHandle nonNullTest = lookup.findStatic(Objects.class, "nonNull",
MethodType.methodType(boolean.class, Object.class)
).asType(MethodType.methodType(boolean.class, cleanerClass));
MethodHandle noop = MethodHandles.dropArguments(MethodHandles.constant(
Void.class,
null
).asType(MethodType.methodType(void.class)), 0, cleanerClass);
MethodHandle nonNullTest = lookup.findStatic(
Objects.class,
"nonNull",
MethodType.methodType(boolean.class, Object.class))
.asType(MethodType.methodType(boolean.class, cleanerClass));
MethodHandle noop = MethodHandles.dropArguments(
MethodHandles.constant(Void.class, null)
.asType(MethodType.methodType(void.class)),
0,
cleanerClass);
MethodHandle unmapper = MethodHandles.filterReturnValue(
directBufferCleanerMethod,
MethodHandles.guardWithTest(nonNullTest, cleanMethod, noop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,13 @@ public static void trySkipCache(int fd, long offset, long len)
catch (UnsatisfiedLinkError ule) {
// if JNA is unavailable just skipping Direct I/O
// instance of this class will act like normal RandomAccessFile
log.warn(ule, "Unsatisfied Link error: posix_fadvise failed on file descriptor [%d], offset [%d]",
fd, offset);
log.warn(ule, "Unsatisfied Link error: posix_fadvise failed on file descriptor [%d], offset [%d]", fd, offset);
fadvisePossible = false;
}
catch (Exception e) {
// This is best effort anyway so lets just log that there was an
// exception and forget
log.warn(e, "Unknown exception: posix_fadvise failed on file descriptor [%d], offset [%d]",
fd, offset);
log.warn(e, "Unknown exception: posix_fadvise failed on file descriptor [%d], offset [%d]", fd, offset);
}
}

Expand All @@ -175,7 +173,11 @@ private static void trySyncFileRange(int fd, long offset, long nbytes, int flags
int ret_code = sync_file_range(fd, offset, nbytes, flags);
if (ret_code != 0) {
log.warn("failed on syncing fd [%d], offset [%d], bytes [%d], ret_code [%d], errno [%d]",
fd, offset, nbytes, ret_code, Native.getLastError());
fd,
offset,
nbytes,
ret_code,
Native.getLastError());
return;
}
}
Expand All @@ -188,8 +190,7 @@ private static void trySyncFileRange(int fd, long offset, long nbytes, int flags
syncFileRangePossible = false;
}
catch (Exception e) {
log.warn(e, "Unknown exception: sync_file_range failed on fd [%d], offset [%d], bytes [%d]",
fd, offset, nbytes);
log.warn(e, "Unknown exception: sync_file_range failed on fd [%d], offset [%d], bytes [%d]", fd, offset, nbytes);
syncFileRangePossible = false;
}
}
Expand Down Expand Up @@ -224,7 +225,10 @@ public static void chunkedCopy(InputStream src, File dest) throws IOException
trySyncFileRange(fd, offset, numBytes, SYNC_FILE_RANGE_WRITE);
if (offset > 0) {
// This does a blocking write-and-wait on any old ranges
trySyncFileRange(fd, lastOffset, lastBytes,
trySyncFileRange(
fd,
lastOffset,
lastBytes,
SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE | SYNC_FILE_RANGE_WAIT_AFTER);
// Remove the old range from the cache
trySkipCache(fd, lastOffset, lastBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ public SegmentMetadataQuery(
// of truth for consumers of this class variable. The defaults are to preserve backwards compatibility.
// In a future release, 28.0+, we can remove the deprecated property lenientAggregatorMerge.
if (lenientAggregatorMerge != null && aggregatorMergeStrategy != null) {
throw InvalidInput.exception("Both lenientAggregatorMerge [%s] and aggregatorMergeStrategy [%s] parameters cannot be set."
+ " Consider using aggregatorMergeStrategy since lenientAggregatorMerge is deprecated.",
lenientAggregatorMerge, aggregatorMergeStrategy);
throw InvalidInput.exception(
"Both lenientAggregatorMerge [%s] and aggregatorMergeStrategy [%s] parameters cannot be set."
+ " Consider using aggregatorMergeStrategy since lenientAggregatorMerge is deprecated.",
lenientAggregatorMerge,
aggregatorMergeStrategy);
}
if (lenientAggregatorMerge != null) {
this.aggregatorMergeStrategy = lenientAggregatorMerge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ private void writeToSingleFile(WritableByteChannel channel) throws IOException
headerOut.size()
);
Preconditions.checkState(
numBytesWritten < fileSizeLimit, "Wrote[%s] bytes, which is too many.",
numBytesWritten < fileSizeLimit,
"Wrote[%s] bytes, which is too many.",
numBytesWritten
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ public void test_abort_afterAllFrames() throws IOException
.frames();

final File file = temporaryFolder.newFile();
final FrameFileWriter fileWriter = FrameFileWriter.open(Files.newByteChannel(
file.toPath(),
StandardOpenOption.WRITE
), null, ByteTracker.unboundedTracker());
final FrameFileWriter fileWriter = FrameFileWriter.open(
Files.newByteChannel(
file.toPath(),
StandardOpenOption.WRITE),
null,
ByteTracker.unboundedTracker());

frames.forEach(frame -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,19 @@ class ByteBuffers

private static long lookupAddressOffset(MethodHandles.Lookup lookup) throws Throwable
{
MethodHandle objectFieldOffset = lookup.findVirtual(UnsafeUtils.theUnsafeClass(), "objectFieldOffset",
MethodType.methodType(long.class, Field.class)
);
MethodHandle objectFieldOffset = lookup.findVirtual(
UnsafeUtils.theUnsafeClass(),
"objectFieldOffset",
MethodType.methodType(long.class, Field.class));
return (long) objectFieldOffset.bindTo(UnsafeUtils.theUnsafe()).invoke(Buffer.class.getDeclaredField("address"));
}

private static MethodHandle lookupGetLong(MethodHandles.Lookup lookup) throws Throwable
{
MethodHandle getLong = lookup.findVirtual(UnsafeUtils.theUnsafeClass(), "getLong",
MethodType.methodType(long.class, Object.class, long.class)
);
MethodHandle getLong = lookup.findVirtual(
UnsafeUtils.theUnsafeClass(),
"getLong",
MethodType.methodType(long.class, Object.class, long.class));
return getLong.bindTo(UnsafeUtils.theUnsafe());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public InputStream openStream()
}
};

Assert.assertEquals((long) (EXPECTED.length * 3), CompressionUtils.gunzip(inputStreamFactory, testFile).size());
Assert.assertEquals(EXPECTED.length * 3, CompressionUtils.gunzip(inputStreamFactory, testFile).size());

Check warning

Code scanning / CodeQL

Result of multiplication cast to wider type

Potential overflow in [int multiplication](1) before it is converted to long by use in an invocation context.

try (final InputStream inputStream = new FileInputStream(testFile)) {
try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(EXPECTED.length * 3)) {
Expand Down Expand Up @@ -712,7 +712,8 @@ public void testGoodGzipWithException() throws Exception
final File gzFile = new File(tmpDir, testFile.getName() + ".gz");
Assert.assertFalse(gzFile.exists());
CompressionUtils.gzip(
Files.asByteSource(testFile), new ByteSink()
Files.asByteSource(testFile),
new ByteSink()
{
@Override
public OutputStream openStream() throws IOException
Expand All @@ -730,7 +731,8 @@ public void flush() throws IOException
}
};
}
}, Predicates.alwaysTrue()
},
Predicates.alwaysTrue()
);
Assert.assertTrue(gzFile.exists());
try (final InputStream inputStream = CompressionUtils.decompress(new FileInputStream(gzFile), "file.gz")) {
Expand Down
Loading