Skip to content

Commit

Permalink
Apply manual style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Dec 9, 2022
1 parent 6e59bd2 commit 958e2a4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
9 changes: 9 additions & 0 deletions checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
"https://checkstyle.org/dtds/suppressions_1_0.dtd">

<suppressions>
<suppress checks="AbbreviationAsWordInName" files="CHMCache.java" lines="11"/>
</suppressions>
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<configuration>
<consoleOutput>true</consoleOutput>
<configLocation>checkstyle.xml</configLocation>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<violationSeverity>warning</violationSeverity>
</configuration>
<dependencies>
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/maxmind/db/BufferHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,21 @@ final class BufferHolder {
ByteBuffer get() {
// The Java API docs for buffer state:
//
// Buffers are not safe for use by multiple concurrent threads. If a buffer is to be used by more than
// one thread then access to the buffer should be controlled by appropriate synchronization.
// Buffers are not safe for use by multiple concurrent threads. If a buffer is to be
// used by more than one thread then access to the buffer should be controlled by
// appropriate synchronization.
//
// As such, you may think that this should be synchronized. This used to be the case, but we had several
// complaints about the synchronization causing contention, e.g.:
// As such, you may think that this should be synchronized. This used to be the case, but
// we had several complaints about the synchronization causing contention, e.g.:
//
// * https://github.com/maxmind/MaxMind-DB-Reader-java/issues/65
// * https://github.com/maxmind/MaxMind-DB-Reader-java/pull/69
//
// Given that we are not modifying the original ByteBuffer in any way and all currently known and most
// reasonably imaginable implementations of duplicate() only do read operations on the original buffer object,
// the risk of not synchronizing this call seems relatively low and worth taking for the performance benefit
// when lookups are being done from many threads.
// Given that we are not modifying the original ByteBuffer in any way and all currently
// known and most reasonably imaginable implementations of duplicate() only do read
// operations on the original buffer object, the risk of not synchronizing this call seems
// relatively low and worth taking for the performance benefit when lookups are being done
// from many threads.
return this.buffer.duplicate();
}
}
36 changes: 17 additions & 19 deletions src/main/java/com/maxmind/db/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class Decoder {

// XXX - This is only for unit testings. We should possibly make a
// constructor to set this
boolean POINTER_TEST_HACK = false;
boolean pointerTestHack = false;

private final NodeCache cache;

Expand Down Expand Up @@ -105,7 +105,7 @@ private <T> DecodedValue decode(Class<T> cls, java.lang.reflect.Type genericType
long pointer = packed + this.pointerBase + POINTER_VALUE_OFFSETS[pointerSize];

// for unit testing
if (this.POINTER_TEST_HACK) {
if (this.pointerTestHack) {
return new DecodedValue(pointer);
}

Expand Down Expand Up @@ -163,9 +163,8 @@ private <T> Object decodeByType(
case ARRAY:
Class<?> elementClass = Object.class;
if (genericType instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) genericType;
java.lang.reflect.Type[] actualTypes
= pType.getActualTypeArguments();
ParameterizedType ptype = (ParameterizedType) genericType;
java.lang.reflect.Type[] actualTypes = ptype.getActualTypeArguments();
if (actualTypes.length == 1) {
elementClass = (Class<?>) actualTypes[0];
}
Expand Down Expand Up @@ -302,9 +301,9 @@ private <T, V> List<V> decodeArray(
@SuppressWarnings("unchecked")
List<V> array2 = (List<V>) constructor.newInstance(parameters);
array = array2;
} catch (InstantiationException |
IllegalAccessException |
InvocationTargetException e) {
} catch (InstantiationException
| IllegalAccessException
| InvocationTargetException e) {
throw new DeserializationException("Error creating list: " + e.getMessage(), e);
}
}
Expand All @@ -325,9 +324,8 @@ private <T> Object decodeMap(
if (Map.class.isAssignableFrom(cls) || cls.equals(Object.class)) {
Class<?> valueClass = Object.class;
if (genericType instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) genericType;
java.lang.reflect.Type[] actualTypes
= pType.getActualTypeArguments();
ParameterizedType ptype = (ParameterizedType) genericType;
java.lang.reflect.Type[] actualTypes = ptype.getActualTypeArguments();
if (actualTypes.length == 2) {
Class<?> keyClass = (Class<?>) actualTypes[0];
if (!keyClass.equals(String.class)) {
Expand Down Expand Up @@ -364,9 +362,9 @@ private <T, V> Map<String, V> decodeMapIntoMap(
@SuppressWarnings("unchecked")
Map<String, V> map2 = (Map<String, V>) constructor.newInstance(parameters);
map = map2;
} catch (InstantiationException |
IllegalAccessException |
InvocationTargetException e) {
} catch (InstantiationException
| IllegalAccessException
| InvocationTargetException e) {
throw new DeserializationException("Error creating map: " + e.getMessage(), e);
}
}
Expand All @@ -388,7 +386,7 @@ private <T> Object decodeMapIntoObject(int size, Class<T> cls)
java.lang.reflect.Type[] parameterGenericTypes;
Map<String, Integer> parameterIndexes;
if (cachedConstructor == null) {
constructor = this.findConstructor(cls);
constructor = findConstructor(cls);

parameterTypes = constructor.getParameterTypes();

Expand All @@ -397,7 +395,7 @@ private <T> Object decodeMapIntoObject(int size, Class<T> cls)
parameterIndexes = new HashMap<>();
Annotation[][] annotations = constructor.getParameterAnnotations();
for (int i = 0; i < constructor.getParameterCount(); i++) {
String parameterName = this.getParameterName(cls, i, annotations[i]);
String parameterName = getParameterName(cls, i, annotations[i]);
parameterIndexes.put(parameterName, i);
}

Expand Down Expand Up @@ -436,9 +434,9 @@ private <T> Object decodeMapIntoObject(int size, Class<T> cls)

try {
return constructor.newInstance(parameters);
} catch (InstantiationException |
IllegalAccessException |
InvocationTargetException e) {
} catch (InstantiationException
| IllegalAccessException
| InvocationTargetException e) {
throw new DeserializationException("Error creating object: " + e.getMessage(), e);
} catch (IllegalArgumentException e) {
StringBuilder sbErrors = new StringBuilder();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/maxmind/db/DecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ private static <T> void testTypeDecoding(Type type, Map<T, byte[]> tests)
MappedByteBuffer mmap = fc.map(MapMode.READ_ONLY, 0, fc.size());

Decoder decoder = new Decoder(cache, mmap, 0);
decoder.POINTER_TEST_HACK = true;
decoder.pointerTestHack = true;

// XXX - this could be streamlined
if (type.equals(Type.BYTES)) {
Expand Down

0 comments on commit 958e2a4

Please sign in to comment.