Skip to content

Commit

Permalink
Drop explicit zeroing at instantiation of Atomic* objects
Browse files Browse the repository at this point in the history
  • Loading branch information
stsypanov authored and jhoeller committed Oct 6, 2020
1 parent b7e1553 commit 8a04910
Show file tree
Hide file tree
Showing 35 changed files with 64 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -182,7 +182,7 @@ static MyAspect myAspect() {
@Aspect
public static class MyAspect {

private final AtomicInteger count = new AtomicInteger(0);
private final AtomicInteger count = new AtomicInteger();

@org.aspectj.lang.annotation.Before("execution(* scheduled())")
public void checkTransaction() {
Expand All @@ -200,7 +200,7 @@ public interface MyRepository {
@Repository
static class MyRepositoryImpl implements MyRepository {

private final AtomicInteger count = new AtomicInteger(0);
private final AtomicInteger count = new AtomicInteger();

@Transactional
@Scheduled(fixedDelay = 5)
Expand All @@ -226,7 +226,7 @@ public interface MyRepositoryWithScheduledMethod {
@Repository
static class MyRepositoryWithScheduledMethodImpl implements MyRepositoryWithScheduledMethod {

private final AtomicInteger count = new AtomicInteger(0);
private final AtomicInteger count = new AtomicInteger();

@Autowired(required = false)
private MyAspect myAspect;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,7 +45,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
@Nullable
private final String methodName;

private final AtomicInteger evaluations = new AtomicInteger(0);
private final AtomicInteger evaluations = new AtomicInteger();


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -286,7 +286,7 @@ public Object postProcessAfterInitialization(Object bean, String beanName) {
}
AtomicInteger c = count.get(beanName);
if (c == null) {
c = new AtomicInteger(0);
c = new AtomicInteger();
count.put(beanName, c);
}
c.incrementAndGet();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -113,7 +113,7 @@ default String greet(String name) {

static class SimpleGreeter implements Greeter {

private final AtomicBoolean cacheMiss = new AtomicBoolean(false);
private final AtomicBoolean cacheMiss = new AtomicBoolean();

@Override
public boolean isCacheMiss() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ protected final class Segment extends ReentrantLock {
* The total number of references contained in this segment. This includes chained
* references and references that have been garbage collected but not purged.
*/
private final AtomicInteger count = new AtomicInteger(0);
private final AtomicInteger count = new AtomicInteger();

/**
* The threshold when resizing of the references should occur. When {@code count}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,7 +44,7 @@ public class CustomizableThreadCreator implements Serializable {
@Nullable
private ThreadGroup threadGroup;

private final AtomicInteger threadCount = new AtomicInteger(0);
private final AtomicInteger threadCount = new AtomicInteger();


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
public class SimpleIdGenerator implements IdGenerator {

private final AtomicLong leastSigBits = new AtomicLong(0);
private final AtomicLong leastSigBits = new AtomicLong();


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public class SpelExpression implements Expression {

// Count of many times as the expression been interpreted - can trigger compilation
// when certain limit reached
private final AtomicInteger interpretedCount = new AtomicInteger(0);
private final AtomicInteger interpretedCount = new AtomicInteger();

// The number of times compilation was attempted and failed - enables us to eventually
// give up trying to compile it when it just doesn't seem to be possible.
private final AtomicInteger failedAttempts = new AtomicInteger(0);
private final AtomicInteger failedAttempts = new AtomicInteger();


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public abstract class AbstractBrokerMessageHandler
@Nullable
private ApplicationEventPublisher eventPublisher;

private AtomicBoolean brokerAvailable = new AtomicBoolean(false);
private AtomicBoolean brokerAvailable = new AtomicBoolean();

private final BrokerAvailabilityEvent availableEvent = new BrokerAvailabilityEvent(true, this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class OrderedMessageChannelDecorator implements MessageChannel {

private final Queue<Message<?>> messages = new ConcurrentLinkedQueue<>();

private final AtomicBoolean sendInProgress = new AtomicBoolean(false);
private final AtomicBoolean sendInProgress = new AtomicBoolean();


public OrderedMessageChannelDecorator(MessageChannel channel, Log logger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void retrieveMono() {

@Test
public void retrieveMonoVoid() {
AtomicBoolean consumed = new AtomicBoolean(false);
AtomicBoolean consumed = new AtomicBoolean();
Mono<Payload> mono = Mono.delay(MILLIS_10).thenReturn(toPayload("bodyA")).doOnSuccess(p -> consumed.set(true));
this.rsocket.setPayloadMonoToReturn(mono);
this.requester.route("").data("").retrieveMono(Void.class).block(Duration.ofSeconds(5));
Expand Down Expand Up @@ -215,7 +215,7 @@ public void retrieveFlux() {

@Test
public void retrieveFluxVoid() {
AtomicBoolean consumed = new AtomicBoolean(false);
AtomicBoolean consumed = new AtomicBoolean();
Flux<Payload> flux = Flux.just("bodyA", "bodyB")
.delayElements(MILLIS_10).map(this::toPayload).doOnComplete(() -> consumed.set(true));
this.rsocket.setPayloadFluxToReturn(flux);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ private static class CountingInterceptor implements RSocket, RSocketInterceptor

private RSocket delegate;

private final AtomicInteger fireAndForgetCount = new AtomicInteger(0);
private final AtomicInteger fireAndForgetCount = new AtomicInteger();

private final AtomicInteger metadataPushCount = new AtomicInteger(0);
private final AtomicInteger metadataPushCount = new AtomicInteger();


public int getFireAndForgetCount() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -86,8 +86,8 @@ public void preSendInterceptorReturningNull() {

@Test
public void postSendInterceptorMessageWasSent() {
final AtomicBoolean preSendInvoked = new AtomicBoolean(false);
final AtomicBoolean completionInvoked = new AtomicBoolean(false);
final AtomicBoolean preSendInvoked = new AtomicBoolean();
final AtomicBoolean completionInvoked = new AtomicBoolean();
this.channel.addInterceptor(new ChannelInterceptor() {
@Override
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
Expand Down Expand Up @@ -119,8 +119,8 @@ protected boolean sendInternal(Message<?> message, long timeout) {
return false;
}
};
final AtomicBoolean preSendInvoked = new AtomicBoolean(false);
final AtomicBoolean completionInvoked = new AtomicBoolean(false);
final AtomicBoolean preSendInvoked = new AtomicBoolean();
final AtomicBoolean completionInvoked = new AtomicBoolean();
testChannel.addInterceptor(new ChannelInterceptor() {
@Override
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,15 @@ public void testOpenEntityManagerInViewFilterAsyncScenario() throws Exception {
final OpenEntityManagerInViewFilter filter2 = new OpenEntityManagerInViewFilter();
filter2.init(filterConfig2);

final AtomicInteger count = new AtomicInteger(0);
final AtomicInteger count = new AtomicInteger();

final FilterChain filterChain = (servletRequest, servletResponse) -> {
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
servletRequest.setAttribute("invoked", Boolean.TRUE);
count.incrementAndGet();
};

final AtomicInteger count2 = new AtomicInteger(0);
final AtomicInteger count2 = new AtomicInteger();

final FilterChain filterChain2 = (servletRequest, servletResponse) -> {
assertThat(TransactionSynchronizationManager.hasResource(factory2)).isTrue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,7 +55,7 @@ class TransactionContext {
@Nullable
private TransactionStatus transactionStatus;

private final AtomicInteger transactionsStarted = new AtomicInteger(0);
private final AtomicInteger transactionsStarted = new AtomicInteger();


TransactionContext(TestContext testContext, PlatformTransactionManager transactionManager,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -177,7 +177,7 @@ void bindingListenerBindListenerOverwrite() {
private static class CountingHttpSessionBindingListener
implements HttpSessionBindingListener {

private final AtomicInteger counter = new AtomicInteger(0);
private final AtomicInteger counter = new AtomicInteger();

@Override
public void valueBound(HttpSessionBindingEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
*/
class ClassLevelDirtiesContextTestNGTests {

private static final AtomicInteger cacheHits = new AtomicInteger(0);
private static final AtomicInteger cacheMisses = new AtomicInteger(0);
private static final AtomicInteger cacheHits = new AtomicInteger();
private static final AtomicInteger cacheMisses = new AtomicInteger();


@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,8 +51,8 @@
*/
class ClassLevelDirtiesContextTests {

private static final AtomicInteger cacheHits = new AtomicInteger(0);
private static final AtomicInteger cacheMisses = new AtomicInteger(0);
private static final AtomicInteger cacheHits = new AtomicInteger();
private static final AtomicInteger cacheMisses = new AtomicInteger();


@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,8 +43,8 @@
*/
class DirtiesContextInterfaceTests {

private static final AtomicInteger cacheHits = new AtomicInteger(0);
private static final AtomicInteger cacheMisses = new AtomicInteger(0);
private static final AtomicInteger cacheHits = new AtomicInteger();
private static final AtomicInteger cacheMisses = new AtomicInteger();


@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -86,7 +86,7 @@ public MyController myController() {
@Controller
private static class MyController {

private AtomicInteger counter = new AtomicInteger(0);
private AtomicInteger counter = new AtomicInteger();


@RequestMapping(value = "/myUrl", method = RequestMethod.OPTIONS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public final Mono<Void> commit(ReactiveTransaction transaction) throws Transacti
private Mono<Void> processCommit(TransactionSynchronizationManager synchronizationManager,
GenericReactiveTransaction status) throws TransactionException {

AtomicBoolean beforeCompletionInvoked = new AtomicBoolean(false);
AtomicBoolean beforeCompletionInvoked = new AtomicBoolean();

Mono<Object> commit = prepareForCommit(synchronizationManager, status)
.then(triggerBeforeCommit(synchronizationManager, status))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ReactorClientHttpResponse implements ClientHttpResponse {
private final NettyDataBufferFactory bufferFactory;

// 0 - not subscribed, 1 - subscribed, 2 - cancelled via connector (before subscribe)
private final AtomicInteger state = new AtomicInteger(0);
private final AtomicInteger state = new AtomicInteger();

private final String logPrefix;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private static class FluxSinkAdapterListener implements NioMultipartParserListen

private final LimitedPartBodyStreamStorageFactory storageFactory;

private final AtomicInteger terminated = new AtomicInteger(0);
private final AtomicInteger terminated = new AtomicInteger();

FluxSinkAdapterListener(
FluxSink<Part> sink, MultipartContext context, LimitedPartBodyStreamStorageFactory factory) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,7 +46,7 @@ public class ServletServerHttpAsyncRequestControl implements ServerHttpAsyncRequ
@Nullable
private AsyncContext asyncContext;

private AtomicBoolean asyncCompleted = new AtomicBoolean(false);
private AtomicBoolean asyncCompleted = new AtomicBoolean();


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*/
class ReactorServerHttpRequest extends AbstractServerHttpRequest {

private static final AtomicLong logPrefixIndex = new AtomicLong(0);
private static final AtomicLong logPrefixIndex = new AtomicLong();


private final HttpServerRequest request;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,7 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements

private AsyncContext asyncContext;

private AtomicBoolean asyncCompleted = new AtomicBoolean(false);
private AtomicBoolean asyncCompleted = new AtomicBoolean();

private final List<Runnable> timeoutHandlers = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void globalResources() throws Exception {
@Test
void globalResourcesWithConsumer() throws Exception {

AtomicBoolean invoked = new AtomicBoolean(false);
AtomicBoolean invoked = new AtomicBoolean();

this.resourceFactory.addGlobalResourcesConsumer(httpResources -> invoked.set(true));
this.resourceFactory.afterPropertiesSet();
Expand Down
Loading

0 comments on commit 8a04910

Please sign in to comment.