-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
qa: fix typehandlerlibrary spotbugs findings #5154
qa: fix typehandlerlibrary spotbugs findings #5154
Conversation
1de72e9
to
655a6f4
Compare
...tems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/serializers/Serializer.java
Outdated
Show resolved
Hide resolved
...rg/terasology/persistence/typeHandling/coreTypes/factories/CollectionTypeHandlerFactory.java
Outdated
Show resolved
Hide resolved
...erLibrary/src/main/java/org/terasology/persistence/typeHandling/inMemory/PersistedBytes.java
Show resolved
Hide resolved
...main/java/org/terasology/persistence/typeHandling/inMemory/arrays/PersistedBooleanArray.java
Show resolved
Hide resolved
...dlerLibrary/src/test/java/org/terasology/persistence/typeHandling/FutureTypeHandlerTest.java
Outdated
Show resolved
Hide resolved
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems to be fixed with spotbugs/spotbugs#2648 but not released yet
we don't fail for spotbugs findings at the moment, so I would not suppress this now but wait for the spotbugs patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree and took it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new spotbug version now included, warnings are gone.
// 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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure we want to suppress this as it might be a valid indicator of improvement potential. Either the private fields are indeed unused then this begs the question why they're in here in the first place. And if they are not explicitly used but implicitly required for the tests, then I would argue that this asks for refactoring due to nontransparent side effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is "just" a type handler test and checks the type? to test nothing needs to be implemented using the fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to test nothing needs to be implemented using the fields.
Sorry, you'll have to elaborate on this, I don't follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved the suppressions to the class which really causes it, when i tried that initially it failed, but cannot reproduce how. its a minimal test case, no point in using these private fields other than by typehandler.
jdrueckert commented on pr: MovingBlocks/Terasology#5154 that the rule is not really beneficial and better remove the rule than suppress it.
@jdrueckert anything else missing? |
af320a2
to
a49261d
Compare
...ology/persistence/typeHandling/coreTypes/factories/ObjectFieldMapTypeHandlerFactoryTest.java
Show resolved
Hide resolved
...erLibrary/src/main/java/org/terasology/persistence/typeHandling/inMemory/PersistedBytes.java
Show resolved
Hide resolved
} | ||
} | ||
|
||
// the test verfies that bot, static class (above), and class work. with this typehandler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spotbugs complains about the inner class ResultCaptor
not being static. I'm not convinced, that the statement "the test verfies that bot, static class (above), and class work. with this typehandler." is correct. The test verifies that for recursive types, the expected typehandler (FutureTypeHandler
) is fetched. For this, it uses ResultCaptor
as a mock to first capture the result and later assert on it.
The reason why it doesn't work making the inner ResultCaptor
class static is that this mock is not a static mock - it doesn't return a pre-defined value but executes the "real" method and captures its result.
Furthermore, the reason why Spotbugs complains about this is that the inner class not being static may result in performance issues due to increased instance sizes and object lifetimes. However, as this is a test, we don't care as much about performance.
...dlerLibrary/src/test/java/org/terasology/persistence/typeHandling/FutureTypeHandlerTest.java
Outdated
Show resolved
Hide resolved
...ology/persistence/typeHandling/coreTypes/factories/ObjectFieldMapTypeHandlerFactoryTest.java
Outdated
Show resolved
Hide resolved
511dbe2
to
0263c33
Compare
842db88
to
4ab80e5
Compare
...erLibrary/src/main/java/org/terasology/persistence/typeHandling/inMemory/PersistedBytes.java
Show resolved
Hide resolved
...main/java/org/terasology/persistence/typeHandling/inMemory/arrays/PersistedBooleanArray.java
Show resolved
Hide resolved
...rg/terasology/persistence/typeHandling/coreTypes/factories/CollectionTypeHandlerFactory.java
Outdated
Show resolved
Hide resolved
4ab80e5
to
885c9eb
Compare
as a workaround, add dependency for spotbugs annotations, and create a [ticket there so the spotbugs gradle plugin would include the dependency] (spotbugs/spotbugs-gradle-plugin#1018). see here a motivation for inner type last rule. if we leave the rule we should respect it, otherwise disable the rule. https://stackoverflow.com/questions/25158939/what-motivation-is-behind-checkstyle-inner-type-last-rule especially in tests just quite the warnings, in most cases the code is deliberate as it is. see MovingBlocks#3859 and see bugs: * pmd/pmd#4731 * spotbugs/spotbugs-gradle-plugin#1018 * spotbugs/spotbugs#2667
now AssertThrows error is fixed: spotbugs/spotbugs#2667
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>
885c9eb
to
2de615c
Compare
when building with java-11 it ends with:
see also #3859