Skip to content

Commit

Permalink
typehandlerlibrary qa, jdrueckert feedback
Browse files Browse the repository at this point in the history
especially take out pmd guardlog suppresses. fix part of them
in a catch even if not necessary from a performance point of
view. and create a pull request towards teraconfig to not
use the guardlog rule any more:
MovingBlocks/TeraConfig#23

Co-authored-by: jdrueckert <jd.rueckert@googlemail.com>
  • Loading branch information
soloturn and jdrueckert committed Nov 18, 2023
1 parent 60b1984 commit 2de615c
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 31 deletions.
3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions build-logic/src/main/kotlin/terasology-metrics.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ dependencies {
// spotbugs annotations to suppress warnings are not included via spotbugs plugin
// see bug: https://github.com/spotbugs/spotbugs-gradle-plugin/issues/1018
compileOnly("com.github.spotbugs:spotbugs-annotations:4.8.1")
pmd("net.sourceforge.pmd:pmd-core:6.55.0")
pmd("net.sourceforge.pmd:pmd-java:6.55.0")
pmd("net.sourceforge.pmd:pmd-ant:7.0.0-rc4")
pmd("net.sourceforge.pmd:pmd-core:7.0.0-rc4")
pmd("net.sourceforge.pmd:pmd-java:7.0.0-rc4")

testRuntimeOnly("ch.qos.logback:logback-classic:1.2.11") {
because("runtime: to configure logging during tests with logback.xml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
* methods that use {@link #serializeToPersisted(Object, TypeInfo)} and {@link #deserializeFromPersisted(PersistedData,
* TypeInfo)}.
*/
// log statements after an if are marked as false positive, suppress.
// see pmd bug: https://github.com/pmd/pmd/issues/4731
@SuppressWarnings("PMD.GuardLogStatementJavaUtil")
public final class Serializer<D extends PersistedData> {

private static final Logger logger = LoggerFactory.getLogger(Serializer.class);
Expand Down Expand Up @@ -87,7 +84,7 @@ public <T> Optional<T> deserialize(TypeInfo<T> type, InputStream inputStream) {
D persistedData = reader.read(inputStream);
return deserializeFromPersisted(persistedData, type);
} catch (IOException e) {
logger.error("Cannot deserialize type [" + type + "]", e);
logger.error("Cannot deserialize type [{}]", type, e);
}
return Optional.empty();
}
Expand All @@ -105,7 +102,7 @@ public <T> Optional<T> deserialize(TypeInfo<T> type, byte[] bytes) {
D persistedData = reader.read(bytes);
return deserializeFromPersisted(persistedData, type);
} catch (IOException e) {
logger.error("Cannot deserialize type [" + type + "]", e);
logger.error("Cannot deserialize type [{}]", type, e);
}
return Optional.empty();
}
Expand Down Expand Up @@ -143,7 +140,7 @@ public <T> void serialize(T object, TypeInfo<T> type, OutputStream outputStream)
try {
writer.writeTo(persistedData.get(), outputStream);
} catch (IOException e) {
logger.error("Cannot serialize [" + type + "]", e);
logger.error("Cannot serialize [{}]", type, e);
}
} else {
logger.error("Cannot serialize [{}]", type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* A serializer provides low-level serialization support for a type, using a mapping of type handlers for each field of that type.
*
*/
@SuppressWarnings("PMD.GuardLogStatementJavaUtil")
public class Serializer {

private static final Logger logger = LoggerFactory.getLogger(Serializer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,6 @@ public <T> TypeHandler<T> getBaseTypeHandler(TypeInfo<T> typeInfo) {
return new RuntimeDelegatingTypeHandler<>(delegateHandler, typeInfo, context);
}

// log after else is false positive, suppress.
// see bug: https://github.com/pmd/pmd/issues/4731
@SuppressWarnings("PMD.GuardLogStatementJavaUtil")
private Map<FieldMetadata<?, ?>, TypeHandler> getFieldHandlerMap(ClassMetadata<?, ?> type) {
Map<FieldMetadata<?, ?>, TypeHandler> handlerMap = Maps.newHashMap();
for (FieldMetadata<?, ?> field : type.getFields()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public PersistedData serializeNonNull(T value, PersistedDataSerializer serialize
return serializer.serialize(value.toString());
}

// log after else is false positive, suppress.
// see bug: https://github.com/pmd/pmd/issues/4731
@SuppressWarnings("PMD.GuardLogStatementJavaUtil")
@Override
public Optional<T> deserialize(PersistedData data) {
if (data.isString()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ private PersistedData serializeEntry(Map.Entry<K, V> entry, PersistedDataSeriali
return serializer.serialize(result);
}

@SuppressWarnings("PMD.GuardLogStatementJavaUtil")
@Override
public Optional<Map<K, V>> deserialize(PersistedData data) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ private String getFieldName(Field field) {
return serializedName.value();
}

// log after else is false positive, suppress.
// see bug: https://github.com/pmd/pmd/issues/4731
@SuppressWarnings("PMD.GuardLogStatementJavaUtil")
@Override
public Optional<T> deserialize(PersistedData data) {
if (!data.isValueMap()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class CollectionTypeHandlerFactory implements TypeHandlerFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(CollectionTypeHandlerFactory.class);

@SuppressWarnings("PMD.UnusedLocalVariable") private ConstructorLibrary constructorLibrary;
private ConstructorLibrary constructorLibrary;

public CollectionTypeHandlerFactory(ConstructorLibrary constructorLibrary) {
this.constructorLibrary = constructorLibrary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.nio.ByteBuffer;

// TODO, see https://github.com/MovingBlocks/Terasology/issues/5176 for reasoning.
@SuppressWarnings({"PMD.ArrayIsStoredDirectly", "PMD.MethodReturnsInternalArray"})
public class PersistedBytes extends AbstractPersistedData {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Arrays;
import java.util.Iterator;

// TODO, see https://github.com/MovingBlocks/Terasology/issues/5176 for reasoning.
@SuppressWarnings({"PMD.ArrayIsStoredDirectly", "PMD.MethodReturnsInternalArray"})
public class PersistedBooleanArray extends AbstractPersistedArray {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ private RecursiveType(T data, RecursiveType<T>... children) {
}
}

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
value = "SIC_INNER_SHOULD_BE_STATIC",
justification = "Test code is not performance-relevant, flagged inner ResultCaptor class is a mock with dynamic behavior" +
" and cannot be static.")
private class ResultCaptor<T> implements Answer {
private T result = null;
public T getResult() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
import java.util.function.Function;
import java.util.stream.Stream;


// spotbugs does thinks Assertions.assertThrows does not throw the exception, even if
// test is successful. see bug: https://github.com/spotbugs/spotbugs/issues/2667.
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings
class InMemorySerializerTest {
private final InMemoryPersistedDataSerializer serializer = new InMemoryPersistedDataSerializer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

// both, pmd and spotbugs complain about not used private fields, suppress in
// the static test class, but fields are checked. suppress.
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings
@SuppressWarnings("PMD.UnusedPrivateField")
public class ObjectFieldMapTypeHandlerFactoryTest {
private final TypeHandlerLibrary typeHandlerLibrary = mock(TypeHandlerLibrary.class);

Expand Down Expand Up @@ -117,6 +113,11 @@ private static class MultiTypeClass<T, U> {
private U u;
}

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
value = "UUF_UNUSED_FIELD",
justification = "Direct member access is not expected. TypeHandler factory dynamically loads type handlers on type handler" +
" creation based on member types of input class TypeInfo. ")
@SuppressWarnings("PMD.UnusedPrivateField")
private static class SomeClass<T> {
private T t;
private List<T> list;
Expand Down

0 comments on commit 2de615c

Please sign in to comment.