Skip to content

Commit

Permalink
category/java/design
Browse files Browse the repository at this point in the history
  • Loading branch information
idelpivnitskiy committed Nov 14, 2023
1 parent a2c16e0 commit 6d87ba7
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class CountDownLatchBenchmark {

private static final Object NULL = new Object();

private CountDownLatch latch = new CountDownLatch(0);
private final CountDownLatch latch = new CountDownLatch(0);

@Nullable
private volatile Object value = NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public Key<?> forEach(final BiPredicate<Key<?>, Object> consumer) {

@Override
public int hashCode() {
return super.hashCode();
return System.identityHashCode(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public ContextMap copy() {

@Override
public int hashCode() {
return super.hashCode();
return System.identityHashCode(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
@Timeout(60)
class MulticastExactlyPublisherTest {
private TestPublisher<Integer> source = new TestPublisher.Builder<Integer>().disableAutoOnSubscribe().build();
private TestSubscription subscription = new TestSubscription();
private final TestSubscription subscription = new TestSubscription();

@Test
void emitItemsAndThenError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
final class OnErrorResumePublisherTest {

private final TestPublisherSubscriber<Integer> subscriber = new TestPublisherSubscriber<>();
private TestPublisher<Integer> first = new TestPublisher<>();
private TestPublisher<Integer> second = new TestPublisher<>();
private final TestPublisher<Integer> first = new TestPublisher<>();
private final TestPublisher<Integer> second = new TestPublisher<>();

@Test
void testFirstComplete() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CompletableToPublisherTest {
@RegisterExtension
static final ExecutorExtension<Executor> EXEC = ExecutorExtension.withCachedExecutor().setClassLevel(true);

private TestPublisherSubscriber<String> subscriber = new TestPublisherSubscriber<>();
private final TestPublisherSubscriber<String> subscriber = new TestPublisherSubscriber<>();

@Test
void invalidRequestNCancelsCompletable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CompletableToSingleTest {
@RegisterExtension
static final ExecutorExtension<Executor> EXEC = ExecutorExtension.withCachedExecutor().setClassLevel(true);

private TestSingleSubscriber<Void> subscriber = new TestSingleSubscriber<>();
private final TestSingleSubscriber<Void> subscriber = new TestSingleSubscriber<>();

@Test
void noTerminalSucceeds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract class AbstractWhenCancelTest {

private final TestPublisher<String> publisher = new TestPublisher<>();
private final TestPublisherSubscriber<String> subscriber = new TestPublisherSubscriber<>();
private TestSubscription subscription = new TestSubscription();
private final TestSubscription subscription = new TestSubscription();

@Test
void testCancelAfterEmissions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class ForEachTest {
private TestPublisher<Integer> source;
private Consumer<Integer> forEach;
private Cancellable cancellable;
private TestSubscription subscription = new TestSubscription();
private final TestSubscription subscription = new TestSubscription();

@SuppressWarnings("unchecked")
@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

class ScalarResultPublisherTest {

private TestPublisherSubscriber<String> subscriber = new TestPublisherSubscriber<>();
private final TestPublisherSubscriber<String> subscriber = new TestPublisherSubscriber<>();

@Test
void testJust() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class ConcatWithCompletableTest {
@RegisterExtension
static final ExecutorExtension<Executor> EXEC = ExecutorExtension.withCachedExecutor().setClassLevel(true);
private final TestSingleSubscriber<String> listener = new TestSingleSubscriber<>();
private LegacyTestSingle<String> single = new LegacyTestSingle<>();
private LegacyTestCompletable completable = new LegacyTestCompletable();
private final LegacyTestSingle<String> single = new LegacyTestSingle<>();
private final LegacyTestCompletable completable = new LegacyTestCompletable();

@Test
void concatWaitsForCompletableSuccess() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,33 @@
<exclude name="InsufficientStringBufferDeclaration"/>
</rule>

<rule ref="category/java/design.xml/CollapsibleIfStatements"/>
<rule ref="category/java/design.xml/MutableStaticState" />
<rule ref="category/java/design.xml/SimplifiedTernary"/>
<rule ref="category/java/design.xml">
<exclude name="AbstractClassWithoutAnyMethod"/>
<exclude name="AvoidCatchingGenericException"/>
<exclude name="AvoidDeeplyNestedIfStmts"/>
<exclude name="AvoidRethrowingException"/>
<exclude name="AvoidThrowingNullPointerException"/>
<exclude name="AvoidThrowingRawExceptionTypes"/>
<exclude name="AvoidUncheckedExceptionsInSignatures"/>
<exclude name="CognitiveComplexity"/>
<exclude name="CouplingBetweenObjects"/>
<exclude name="CyclomaticComplexity"/>
<exclude name="DataClass"/>
<exclude name="DoNotExtendJavaLangError"/>
<exclude name="ExcessiveImports"/>
<exclude name="ExcessiveParameterList"/>
<exclude name="ExcessivePublicCount"/>
<exclude name="GodClass"/>
<exclude name="LawOfDemeter"/>
<exclude name="NPathComplexity"/>
<exclude name="NcssCount"/>
<exclude name="SignatureDeclareThrowsException"/>
<exclude name="SingularField"/>
<exclude name="SwitchDensity"/>
<exclude name="TooManyFields"/>
<exclude name="TooManyMethods"/>
<exclude name="UseUtilityClass"/>
</rule>

<!-- generated -->
<exclude-pattern>.*/generated/source/proto/.*</exclude-pattern>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ void testCustomTransport(final ServiceType serviceType) throws Exception {
// Build the client with the custom transport and bridge to server's transport.
Tester.TesterClient client = new Tester.ClientFactory() {
@Override
@SuppressWarnings("PMD.UselessOverridingMethod")
// Override to alter visibility modifier
public TesterClient newClient(final GrpcClientCallFactory factory) {
return super.newClient(factory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public HttpResponseStatus status() {
}

@Override
public String toString() {
@SuppressWarnings("PMD.UselessOverridingMethod")
public String toString() { // FIXME: 0.43 - remove method that was kept only for ABI backward compatibility
return super.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AsyncContextInMemoryScopeManagerTest {
@Mock
private InMemorySpan mockSpan2;

private AsyncContextInMemoryScopeManager scopeManager = (AsyncContextInMemoryScopeManager) SCOPE_MANAGER;
private final AsyncContextInMemoryScopeManager scopeManager = (AsyncContextInMemoryScopeManager) SCOPE_MANAGER;

@BeforeEach
public void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FlushStrategiesTest {
private FlushSender flushSender;
private TestPublisher<String> durationSource;
private WriteEventsListener listener;
private TestSubscription subscription = new TestSubscription();
private final TestSubscription subscription = new TestSubscription();

@BeforeEach
public void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ class Scenarios {
private RequestResponseCloseHandler h;
@Nullable
private CloseEvent observedEvent;
private AtomicBoolean closed = new AtomicBoolean();
private AtomicBoolean inputShutdown = new AtomicBoolean();
private AtomicBoolean outputShutdown = new AtomicBoolean();
private final AtomicBoolean closed = new AtomicBoolean();
private final AtomicBoolean inputShutdown = new AtomicBoolean();
private final AtomicBoolean outputShutdown = new AtomicBoolean();
private SocketChannelConfig scc;

/**
Expand Down

0 comments on commit 6d87ba7

Please sign in to comment.